Showing posts with label Access Modifiers. Show all posts
Showing posts with label Access Modifiers. Show all posts

Saturday, June 1, 2013

Access Levels

Access Levels are defined using access modifiers and combinations of access modifiers, access levels define different levels of accessibility to classes and its members by specifying an individual access modifier or combining access modifiers.

The following are the available Access Levels in C#

Friday, May 31, 2013

Internal Access Modifiers

Members declared with internal access modifiers can be accessed from within the same assembly in which the member is defined.  These members can also be accessed from other classes which reside in the same assembly.

The following example defines an internal variable
strInternalName.

Protected Access Modifiers

Members declared with protected access modifiers can be accessed from within the class and from any class which derives from the class which defines the members. These members are not visible to external classes which do not derive from the underlying class.

The following example defines a protected variable
strProtectedName.

Public Access Modifiers

This is the most lenient of all the access modifier, any member of the class which is defined public can be accessed from anywhere inside or outside of the class. Members defined with this modifier provide no restriction in getting or setting the values.

The following example defines a public variable
strPublicName.

Private Access Modifiers

This is the most restrictive access modifier, any member of the class which is defined private cannot be accessed from outside the class, these members are visible only within the class, trying to access these members outside the class will result in a compilation error.

The following example defines a private variable
strPrivateName.

What are Access Modifiers?

Access modifiers are keywords which are used to define the scope / accessibility of class members. Access modifier keywords should be added in front of the variable or function to define its scope.

The following are the 4 access modifiers available in C# .Net