C sharp Access Modifiers

9:45 AM Viduruwan Suvinith 0 Comments


C sharp is a one of Dot.Net language.C sharp has qualities of both C++ and Java.Some time people find it difficult to be convert to C sharp from Java or C ++ . True there is a difference.But that difficulty  can handle  by studying about the basic concepts of C sharp.

Today I'm going to give a summarized table about details of  access modifiers in C sharp. C sharp contain 5 access modifiers. Following table shows access level of these modifiers.


Access Modifier

Condition
PrivatePublicInternalProtectedProtected Internal
Different Class same assemblyNOYESYESNOYES
Derived class same assemblyNOYESYESYESYES
Different assembly another classNOYESNONONO
Derived class different assemblyNOYESNOYESYES

Another things most of people has mistaken that packages in Java is equal to namespace.Yes it is equal but not in access modifiers levels. Even thought both are using to contain and organize classes in logical manner  Namespace does not affect to access levels.

Finally we can conclude access level as follow

Access Modifier

Description

public

Signifies that the member is accessible from outside the class's definition and hierarchy of derived classes.

protected

The member is not visible outside the class and can be accessed by derived classes only.

private

The member cannot be accessed outside the scope of the defining class. Therefore, not even derived classes have access to these members.

internal

The member is visible only within the current compilation unit. The internal access modifier creates a hybrid ofpublic and protected accessibility depending on where the code resides.


protected internal

The member is visible  within the current compilation unit and derived classes only.


You Might Also Like