Object oriented
1. Class: The abstraction of many objects
2. Object: Class instantiation
3. Definition of Class
Keyword class
4. The class contains
Member variables
Member properties
Member Methods
5. Object-oriented three major features
(1) Package
Purpose: Protect classes and make classes more secure.
Procedure: Make the member variable inside the class private, do the corresponding method or property to indirectly manipulate the member variable
Encapsulates member methods to indirectly manipulate member variables inside a class
Use member properties to indirectly access member variables inside 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 has access to all places
Constructor method (function):
Function: The method to be called by the object to create the object, which can be initialized to the member
Every class has a method of construction, and there's nothing to write about, just to see.
Particularity: Special execution time is special
This keyword:
This represents the object and does not represent the class
(2) Inheritance:
Concept: Subclasses can inherit everything from the parent class
Features: Single inheritance A subclass can have only one parent class, and a parent class may have more than one child class (all parent classes are object)
Base keyword
Sealed keyword: Sealed class This class cannot be inherited
Partial classes: Partial can split a class into multiple parts, placed within multiple files
The namespace namespace is equivalent to a virtual folder
(3) Polymorphism:
1. Compiling polymorphic
function overloading
2. Run polymorphic
Concept: When a parent class refers to a subclass instance, because the subclass overrides the method of the parent class, the difference in calling the method is called polymorphic
Condition: Must have an inherited parent class reference to a subclass real example class must be overridden by a method in the parent class
The principle of substitution on the Richter scale: if there is a place to use the parent class object, you can give him a subclass object
1. Function overloading
function overloading requires the same function name, number of arguments, or different types of parameters
2.this keywords
Although it is written in a class, it does not belong to the class, but belongs to the object's
In general, in a class The This keyword can be omitted, but if there is a method parameter name and member name duplicate, this is the time to call the members of the object to add the This keyword
3. is keyword
Determine if a variable is 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, child class objects may be converted to parent class objects)
5. Inheritance
Subclasses can inherit everything from the parent class
Features: Single inheritance
A subclass can have only one parent class A parent class may have more than one child class
C # Special points: Ancestors of all classes are object
Base keyword: Represents the parent class object in a subclass with the same usage and this keyword
If the parent class has a constructor, the subclass must also have a constructor method, and if the parent constructor requires parameters, then the subclass constructs have to have corresponding parameters.
The construction of the parent class can be called by base after the subclass construct
Public China (string m): Base (m)
{
}
SQL encapsulation, polymorphism, and overloading