Modifier
Modifiers are keywords that apply to types or members . Modifiers can specify the visibility of a method , such as public or private, and you can specify the nature of an item , such as a vritual or abstract that has just been sent.
Modifiers for visibility
Modifier |
Applied to |
Description |
Public |
All types or members |
Any code can access the item |
Protected |
All members of type and inline type |
Only derived types can access the item |
Internal |
All types or members |
The item can only be accessed in the assembly that contains it |
Private |
All members of type and inline type |
The item can only be accessed in the type to which it belongs |
protected internal |
All members of type and inline type |
The item can only be accessed in any code that contains his assembly and derived types |
Note that the definition of a class can only be internal or public , depending on whether you want to access it outside of the assembly that the type contains :
public class MyClass
{}
The type cannot be declared asProtected,private,Andprotected internal, Because these modifiers have no meaning for the types contained in the namespace . So these modifiers can only be applied with members . But , You can use these modifiers to define nested types (, contains types because in this case , Type also has member status . So the following code is legal :
public class Outerclass
{
Protected class Innerclass
{}
}
If there is a nested type , the internal type always has access to all members of the external type . So , in the code above,the code in Innerclass can access all members of the Outerclass , and even the private members of Outerclass can access .
Other modifiers
Modifier |
Applied to |
Description |
New |
Function members |
Members with the same signature hide inherited members |
Static |
All Members |
Members do not make specific instances of the class |
Vritual |
Function Members Only |
Members can be overridden by derived classes |
Abstract |
Gold function member |
The virtual member defines the signature of the member and does not provide the implementation code |
Override |
Function Members Only |
A member overrides an inherited virtual or abstract member |
Sealed |
Classes , methods, and properties |
For classes , you cannot inherit from a sealed class . For properties and Methods , a member overrides an inherited virtual member , but no member of any derived class can override the school-constant source . The modifier must be used with override |
extern |
static method only |
Members are externally implemented in the Ning Yizhong language . |
C # Programming (24)----------modifiers