Definition class
In C #, use the class keyword, a name, and a pair of braces to define a new class. The data members and methods of the class are located within the class body (between a pair of braces)
Class syntax format
Class myclass
{
// Subject of the class
}
Class Modifier
When defining a class, you can add an access modifier before the class. The class modifier is used to control the accessed range. By default, the class modifier is internal.
We can see that we added private, protected,All protected internal compilation errors, so only these two class modifiers are supported. One is internal, and the other is public.
1: Internal
The default value is internal when nothing is written.
Only oneProgramCentralized
2: Public
There is no level limit on access members, and the class can be accessed anywhere
The meclass can be instantiated in callmeclass. Cs in the classlibrary1 project. This is because they can be instantiated in a classlibrary1.dll file, that is, they are all in a set of programs.
Running. When we add a public modifier before the class name in the classes Class, we can compile it and break through the restrictions.
Class member Modifier
1: Private
Can only be accessed within the class
2: Internal
Access is limited to a set of Programs
3: Protected
Can only be accessed in the class and the class's derived class, regardless of whether the derived class and the base class are in the same assembly
4:Protected internal protected internal
If it is an inheritance relationship, it can be accessed in the same set of programs. If it is not an inheritance relationship, it can only be accessed in the same set of programs.
5: Public
There is no level limit on access members, and the class can be accessed anywhere
Access permission
Create a Class Object
Create a class instantiation object in C # and use the new keyword.
The class we define belongs to the custom type and also the reference type. Therefore, we can instantiate this class with the new keyword.