Thursday, 4 July 2013

Access Specifier C#

What is the usage of access specifier ?

Access specifier is used to specify the what type of access can given for method,class,variable,property, event when it is try to invoke from other class , other class which is present in other project. In C# there is various Access Specifiers

1. Public
2. Private
3. Protected
4. Internal
5. Protected Internal

Here Assembly consider as Project in IDE

public
The type or member can be accessed by any other code in the same assembly or another assembly that references it.
private
The type or member can be accessed only by code in the same class or struct.
protected
The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class.
internal
The type or member can be accessed by any code in the same assembly, but not from another assembly.
protected internal
The type or member can be accessed by any code in the assembly in which it is declared, or from within a derived class in another assembly. Access from another assembly must take place within a class declaration that derives from the class in which the protected internal element is declared, and it must take place through an instance of the derived class type.

No comments:

Post a Comment