One: three main features of object-oriented
Encapsulation, inheritance, polymorphism
Packaging
1: The concept and role of encapsulation
* Use the private and public modifiers to modify the members of the Class (fields, properties, methods, etc.) so that the private data and methods are not accessible to the outside world, which is encapsulation;
* A property, a method is also encapsulated, the class is the encapsulation of properties and methods;
* Encapsulation is an important feature in object-oriented, and the three important features of object-oriented are: encapsulation, inheritance, polymorphism;
* Role < modularity and data hiding >
2: A class is a template that determines the characteristics (attributes) and behavior (methods) that an object will have, and any object will belong to a class;
3: The object is created by the class as a template, is the instantiation of the class, materialized;
4: Object-oriented benefits
* Packaging allows developers to pay more attention to their own needs;
* Once a class is defined, it can be used multiple times to avoid duplicate assignment;
5: Class attempts to show the overall structure of the class; Class (Right------view class diagram)
6: Ancestor of Class (object)
The *object class is the parent class of all classes (ancestor classes), so any class can be converted to the object type;
* You can assign any type of value to a variable of type object;
Boxing: The process of converting a variable of a value type to a <object> object is called boxing;
Unpacking: The process of converting a variable of <object> object type to a value type is called unpacking;
Inherited
* One class inherits from another class, the first class is called a subclass, the other is called the parent class, the subclass inherits the parent class, that is, the subclass has the properties and methods of the parent class, can override the <override> parent class's methods and properties, and the subclass can edit its own properties and methods. <object class >
* Subclasses cannot inherit private members of parent class
* Subclasses can have only one parent class, but a class that is a parent is a parent class of multiple subclasses.
1: Keyword virtual
The virtual keyword is used to specify that a property or method is overridden in a derived class. By default, a derived class inherits properties and methods from its base class, and if the inherited property or method requires different behavior in the derived class, you can override it to define a new implementation of the property or method in the derived class. At this point in the base class, the property or method must be decorated with the virtual keyword. The virtual keyword can be overridden in a derived class when it is used to specify a property or method. A method or property with the virtual keyword is called a dummy member.
Declare a virtual method with the virtual modifier in the base class (the parent Class), and then overwrite the base class virtual method with the override modifier in the derived class (subclass). Indicates that the virtual method overload is on the base class. The advantage is that it can decide which method to invoke when the program is run, which is called "Runtime polymorphism", or dynamic binding.
Class A {public virtual void F () {} } class b:a {public override void F () {} }
Polymorphic < compile-time polymorphism, run-time polymorphism >
* As with the definition of overloading, it can be said that overloading is also polymorphic.
* Defining the inheritance of classes occurs between multiple classes, and the polymorphism of a class occurs on the same class, where multiple methods of the same name can be defined in a class, as long as the number and type of arguments are different.
Understanding the polymorphism is understood in the following paragraph.
Overwrite: The subclass has a method and a property with the same name as the parent class, at which time the method of the parent class overrides the quilt class. Equivalent to modifying the method of the parent class.
Two: Object data type and object destruction
1: Basic data type {Int,double,bool ...}, value type;
Reference data type {array, object, string}, object type;
2: * When the reference type variable is passed, assign its own memory address to the new variable {pointer};
* When a value type variable is passed, it copies itself;
The value type is stored in the stack, and the reference type, part is stored in the heap, and a part is stored inside the stack.
3:ref keywords
Value type variables can be passed by reference; {It is not recommended to use the REF keyword frequently in real-world development}
The reference parameter must be initialized,
4:out keywords
You can have multiple return values for the method, with emphasis on the output, reference to the parameter, and no initialization, but must be assigned within the method. <return multiple return values inside the >
5:params: Used when more than one parameter is required. The array type parameter.
6: Destruction of objects
Garbage collection mechanism (GC)
*.net the virtual machine-specific mechanism, automatically run, and check the state of the object;
* When the object is not referenced, it will release the occupied space;
* In practical applications we can call the GC ourselves to help us clean up some variables and fields that we don't need.
Three: non-generic collections
1:arraylist is a variable-length "array", usually a set, similar to the structure of an array, the largest of which is the freedom to expand the number of elements;
Features of the 2:arraylist collection
* elements are converted to type Object
* Use the Add method to add arbitrary elements, no limit;
* Use the Remove method to delete the specified element, the index automatically adjusts after the element is deleted;
* The element is accessed by an index, and the element needs to be cast to a specific data type when it is removed;
3:arraylist the specific insert, delete code;
Knowledge of 4:icollection<t> Generics
* Ilist<t> inherits from Icollection<t>,icollection<t> inherited from Ienumerable<t>,ienumerable<t> Inherit from IEnumerable
So the list<t> implements the Ilist<t> interface, which is the IEnumerable interface.
* ienumerable<t> is a generic version of the IEnumerable interface. With generics, the value types are not forced to be boxed and unboxing, or reference types are forced down to type conversions, which improves program performance. Generic definitions have type restrictions, so generics improve the type-safety of the program. Generics also improve the reusability of code.
Four: The use of generic set list<t> and dictionary
1:list<t> Pre-use preparation work
* Introducing Namespaces: System.Collections.Generic
* Determine the storage type:list<student> student=new list<student> ();
Common methods
* Added element: Add (<T>);
* Delete element: RemoveAt (index);
* Number of elements: Count
Iterating through the collection
Foreach (Student stu in students) { Console.WriteLine (stu.studentname); }
2: The largest feature of a generic set: Strictly constraining the type of elements within the set;
3: Set initializer
When creating a collection object, it is initialized directly, very similar to an array;
4:dictionary<k,v> is often referred to as a dictionary
*<k,v> element types in a constrained collection
* Compile-time check type constraint;
* No packing and unpacking operation
* With hash table Operation Class View
Object-oriented Foundation advanced