Access Modifiers

Access Modifiers

 

C# supports the following access modifiers, which you can use when declaring a class, method, or property:

 

Public: A public class, method, or property has no access restrictions.

 

Protected: A protected method or property can be accessed only within the class

itself or a derived class.

 

Internal: An internal class, method, or property can be accessed only by a component

within the same assembly (dll file). Because ASP.NET pages are compiled into

different assemblies than the contents of the App_Code folder, you cannot access an

internal member of a class outside of the App_Code folder.

 

Private: A private class, method, or property can be accessed only within the class

itself.

 

Visual Basic .NET supports the following access modifiers (also called access levels), which

you can use when declaring a class, method, or property:

 

Public: A Public class, method, or property has no access restrictions.

Protected:A Protected method or property can be accessed only within the class

itself or a derived class.

 

Friendโ€”A Friend class, method, or property can be accessed only by a component

within the same assembly (dll file). Because ASP.NET pages are compiled into different

assemblies than the contents of the App_Code folder, you cannot access a Friend

member of a class outside of the App_Code folder.

 

Protected Friendโ€”A Protected Friend method or property can be accessed within

the class itself or a derived class, or any other class located in the same assembly.

 

Privateโ€”A Private class, method, or property can be accessed only within the class

itself.

 

Next Recommended Reading Access modifer