Access Specifiers or Access modifiers - DotNet and DataBase

Follow us on Facebook

SQL Server Mountain View Mountain View Mountain View

Saturday, 14 July 2018

Access Specifiers or Access modifiers

Access modifiers or specifiers defines the scope of accessibility of  a class members.
.Net framework provides five types of access specifiers

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

Public is universal, we can access public members in the same class, instance classes, derived classes and other assemblies also. There is no restriction to use. So, it is universal access modifier.

public datatype variablename;
public returntype methodname();

Private is strongly restricted for the same class/same method.

private datatype variablename;
private returntype methodname();

internal works same as public, but the scope restricts for the same assembly. We can access through object or inherit, but other assembly we can't access either though object or inherit.

internal datatype variablename;

"protected" member can be access through inheritance only. We can access protected in the same assembly or derived assembly through inherit only.

protected datatype variablename;

protected internal:
protected internal member can be accessed through object or inherit with in the same assembly,  access through inherit only on other assembly.
It is the combination of "protected" and "internal".

protected internal datatype variablename;

No comments:

Post a comment


Get Updates On

Discussion updates

Straight Into Your INBOX!

Enter your email address to subscribe to this website and receive notifications of new posts by email.