Object-oriented
1. Class: Abstract from many objects
2. Object: Class instantiated
3. Definition of Class
Keyword class
4. The class contains
Member variable
Member properties
Member Methods
5. Object-oriented three major characteristics
(1) Package
Purpose: To protect classes and make classes more secure.
Practice: Let the member variables inside the class into private, do the appropriate method or attribute to indirectly manipulate the member variables
Encapsulates member methods to indirectly manipulate member variables within a class
Use member properties to indirectly access member variables within a class
Access modifiers
Private private can only be accessed in this class
Protected protected can only be accessed in this class and its subclasses
Public access is available anywhere
Constructor method (function):
The method to be invoked to create an object that can be initialized to a member
Each class has a construction method, not written, but not visible.
Particularity: Special execution time of writing special
This keyword:
This represents the object and does not represent the class
(2) Inheritance:
Concept: Subclasses can inherit everything from the parent class
Feature: Single inheritance A subclass can have only one parent class, and a parent class may have multiple subclasses (all parent classes are object)
Base keyword
Sealed keywords: Sealed class This class cannot be inherited
Part of class: Partial can split a class into multiple parts, and put them in multiple files
namespace namespaces are equivalent to virtual folders
(3) Polymorphism:
1. Compile polymorphism
Function overload
2. Run polymorphic
Concept: When a parent class reference points to a subclass instance, because the subclass's method of the parent class is overridden, the difference in the invocation of the method is called polymorphism
Condition: Must have inherited parent class reference point to subclass real example class must override method of parent class
The Richter substitution principle: If there is a place to use the parent object, then you can give him a subclass object
1. Function overload
Condition required for function overloading: function name to be the same, number of arguments or type of parameter different
2.this keywords
Although it is written in the class, but not in the class, it belongs to the object's
Generally within the class the This keyword can be omitted, but if there is a method parameter name and member name repetition, then call the member inside the object need to add the This keyword
3. is keyword
Determines whether a variable belongs to a type
If (y2 is Ren)
{
s = ' is a person ';
}
Else
{
s = "not a person";
}
4. As keyword
Conversion type (only compatible types can be converted, the subclass object may be converted to the parent class object)
5. Inheritance
Subclasses can inherit everything from the parent class
Features: Single inheritance
A subclass can have only one parent class, and one parent class may have multiple subclasses
C # Special points: Ancestors of all classes are object
Base keyword: Represents a parent class object in a subclass, with the same usage as the This keyword
If the parent class has a construction method, the subclass also has a construction method, and if the parent constructor requires parameters, the subclass construct must also have corresponding parameters.
The constructor method of the parent class can be invoked by base after the subclass construct
Public (string m): Base (m)
{
}
The above is a small set to introduce the SQL package, polymorphism and overloading, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!