183k views
0 votes
What are the field/method access levels (specifiers) and class access levels ?

1 Answer

5 votes

Answer:

There are 5 access specifiers totally in C#

Step-by-step explanation:

In C# there are 5 different access specifiers.

1. Private

2. Protected

3. Internal

4. Protected Internal

5. Public

Fields or methods can have all the access modifiers, where as classes can have only 2 (internal, public) of the 5 access specifiers.

I have explained the usage of each access modifier below.

Private :

Private members are available only with in the containing type.

Public :

Public members are available any where. There is no restriction.

Internal: Internal members are available anywhere in the containing assembly.

Protected:

Protected Members are available, with in the containing type and to the types that derive from the containing type.

Protected Internal :

These are available anywhere within containing assembly and from within a derived class in any another assembly.

User Torc
by
5.1k points