- public: Access is not restricted.The item is visible to any other code.
- protected: Access is limited to the containing class or types derived from the containing class.The item is visible only to any derived type.
- Internal: Access is limited to the current assembly.The item is visible only within its containing assembly.
- protected internal: Access is limited to the current assembly or types derived from the containing class.The item is visible to any code within its containing assembly and also to any code inside a derived type.
- private: Access is limited to the containing type.The item is visible only inside the type to which it belongs.
Method Access Modifiers
If no modifier is specified, the method is given private access
- public indicates the method is freely accessible inside and outside of the class in which it is defined.
- internal means the method is only accessible to types defined in the same assembly.
- protected means the method is accessible in the type in which it is defined, and in derived types of that type. This is used to give derived classes access to the methods in their base class.
- protected internal means the method is accessible to types defined in the same assembly or to types in a derived assembly.
- private methods are only accessible in the class in which they are defined.
- virtual methods can be overriden by a derived class using the override keyword.
- abstract methods must be overriden in a derived class. If any method of a class is abstract, the entire class must be declared as abstract.
- sealed methods are methods that override an inherited virtual method having the same signature. When a method is sealed, it cannot be overriden in a derived class.
Class Modifiers
The class is one of the two basic encapsulation constructs in C# (the other being the struct). Every executable statement must be placed inside a class or struct. Classes define reference types that are the basic building blocks of C# programs, and they are the architectural blueprint for the "objects" in OOP.
- abstract: An instance of the class cannot be created.Usually this means the class is intended to serve as a base class.
- sealed: The class cannot serve as a base class for another class (it can't be derived from). A class cannot be both abstract and sealed.
- internal: The class is only accessible from other classes in the same assembly. This is the default access for non-nested types. If no modifier is specified, the class has internal access.
- new: Used only with nested classes. "New" indicates that the class hides an inherited member of the same name.
- private: A nested class that can only be accessed inside the class in which it is defined.
- public: Instances of this class are available to any class that wants to access it.
No comments:
Post a Comment