C# video study notes (2)

1. Exception handling

  	    try  
            {
               // code where exception may occur
            }
            catch
            {
               //When an exception occurs, the content displayed
            }

 
 

2. Method

	 [access modifier] static return value method name ([parameter list])
 	 {
             //method
         }

	 // call the method
            Program.Show();
            Show();

3. Objects and Classes

      Object: visible, tangible, specific, specific For example: Langfang No. 1 Middle School Class 6 class teacher so-and-so

      Class: is a template, an abstract concept. eg: teacher


4. Properties and methods

The characteristics of a person can be understood as the attributes of the person


              A person's behavior can be understood as the person's method

//property
public string Name
    {
           get { return _name; }//read
           set { _name = value; }//write
     }
//method
public void SayHello()
      {
            Console.WriteLine("hello everyone, I'm human, my age is {0}",Age );
      }         

5. Constructor

    The (overloaded) constructor is a special method used to create an object. The method name is the same as the class name, and there is no return value, not even void. Constructors can have parameters, and you can pass function parameters when creating a new object. If no constructor is specified, the class has a default no-argument constructor. If a constructor is specified, there is no longer a silent no-argument constructor. If you want a no-argument constructor, you need to write it yourself

 
 
// overloading the constructor
      public Person(string name, char gender, int age)
      {
          this._name = name;//Indicative pronoun
          this._gender = gender;
          this._age = age;
      }
      public Person(string name)
       {
          this._name = name;
      }
      public Person()
       {
      }
//The client calls
static void Main(string[] args)
   {
           Person per=new Person("Zhang San",'male',18);
           Person p = new Person("Zhang San");
   }       

6. Strings

   Case conversion: ToLower to lowercase ToUpper to uppercase

   Remove / split: String[] Split(params char[] separator): Split the string into characters according to the specified separator


7. Value Types and Reference Types

The value of the value type is stored on the stack, the reference typeAddresses are stored on the stack, and values ​​are stored on the heap

    类当中默认的有一个无参数的构造函数,当在类中写一个有参数的构造函数,默认的无参数的构造函数被干掉了,类中写构造函数参数列表中参数个数可以不确定。

    在结构中默认的也有一个无参数的构造函数,当在结构中写一个有参数的构造函数,默认的无参数的构造函数还有,没被干掉。在结构中写构造函数,要把所有的字段都要完全赋值。

    类是引用类型,结构是值类型。

8.继承

      子类与父类   派生类与基类

      子类中如果有有参数的构造函数,会默认的去调用父类中的无参数的构造函数。解决方案:在父类中写出无参的构造函数或者在子类中调用是加上:base(参数1,2,3);

9.集合

     往集合中添加数据有三种方式:

          通过构造函数可以添加一个数组

          通过Add()方法可以添加数组,-----但是算成一个元素

          通过AddRange()也可以添加数组,----


10.哈希表

        以键值对的形式存值      key----键,value---值    其中,key不能重复,是无序的


(未完待续...)



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325917437&siteId=291194637