1. What is a class?
A class is an abstract data type and a unified description of a class of objects. In our life, we often classify things with the same characteristics into one category.
Class declaration Syntax:
<Access modifier> class Name
{
// Subject of the class
}
All executed code must be included in the class and there is no code other than the class. This is the requirement of C.
For example, when creating a car class: public class
{
// Automobile attributes and Methods
}
2. Access Modifier
C # specifies that the class access modifier is internal by default, and the class member's default access modifier is private
The access modifier is used to specify the access permissions for the modified classes, attributes, and methods.
3. Relationship between classes and objects
Classes and objects are inseparable. classes have objects, objects have classes, and everything in the world can be seen as objects. To think about problems with object-oriented thinking, we must regard everything as an object.
Objects cannot be separated from classes. A class is a description of a group of objects with common features. objects are classified into classes, and objects are specific manifestations of classes.
In different situations, we have different perspectives, different classification standards, and different objects. In programming, objects vary according to different requirements.
The process from abstraction to concrete is the process of instantiating class attributes and behaviors.
4. Constructor
The constructor name has the same name as the class. No value is returned.
The constructor is automatically called every time a class is created.
Used to initialize variable members
5. new keywords
A new object can be instantiated.
Create a constructor for a parameter
6. method call steps
Instantiation
Object Name. Method Name ([parameter])
7. classes that cannot be inherited by the quilt class are called sealing classes.
8. Attributes
Sometimes it is insecure to expose fields in the class.
If the attribute in the class is set as a private member, the assignment cannot be normally assigned and data cannot be obtained.
C # use attributes to read and write fields without directly reading or writing them. This provides protection for fields in the class.
Attribute can be used to encapsulate fields in a class.
Attribute stone C # effective embodiment of encapsulation in object-oriented technology.
Attribute can usually be accessed through the accessor (get, set) to operate on the field
There are three different types of attributes: read/write attributes, read-only attributes, and write-only attributes.
Apply static attributes and static attributes to the entire class rather than the instance of the class.
Static attribute access method: Class Name. Static attribute name
Attribute is a logical Field
Attribute is field extension
Different from fields, attributes do not directly correspond to storage locations.
The attribute is essentially a method, but it is different from the method representation. The attribute is not applicable to square brackets.
<Object initiator>
9. Encapsulation
Encapsulation is one of the three main characteristics of object-oriented
Encapsulation advantages: avoid unauthorized data access and ensure data integrity
10. Indexer
The indexer is a special attribute in C #.
After creating an index for an array, you can specify an index for the instance object to directly access the array element.
You can index an object using an index array.
The indexer does not point to the memory location.
The indexer can have a non-integer table (INDEX)
You can reload the indexer.
The rule for defining the indexer is: you must specify at least one indexer parameter to assign a value to the indexer parameter.