In C #, classes are "blueprints" that are abstracted and summed up from objective things.
Class members include
1. Attributes: Used to describe the characteristics of an object
2. Method: Describe the behavior of the object
3. Event: Behavior triggered under certain conditions
4, constructor: Also called the constructor, constructs the method.
Class definition uses the class keyword
Class Test
{
Members of the class
}
Field
A field is a variable defined inside a class or struct
struct POINT
{
public int x;
public int y;
}
Chass Student
{
String name;
int age;
String assress;
}
The above defines a student class containing three fields
Public access. Not subject to any restrictions.
Private access. This class is restricted to access by members, subclasses, and instances.
protected protected Access. This class and subclass access is limited, and instances cannot be accessed.
Internal internal access. Access is limited to this item and cannot be accessed by others.
protected internal internal protection access. Limited to this item or subclass access, other inaccessible
Property:
Properties are used to describe the characteristics of a class, which can encapsulate a field. Usually with get: the value and set used to get the property: The value used to set the property
in the properties can also be set, this setting is worth the condition
Add this condition so that the setting will be an error. throw new Araumentexception ("message") is used to output error messages
You can use the simplified attribute declaration syntax if the property value does not require special validation processing
Write only get; indicate that this property is read-only
C # class