What are the access-specifiers available in c#?

Answer Posted / kedarnath

1.Private:Members declared as private under a class or structure can’t be accessed outside of the type in which they are defined and moreover their scope is private only. Types cannot be declared as private where it is applicable only to members.
NOTE: Interfaces cannot contain any private members in them and default scope for interface members is public.
2.Protected:Members declared as protected under a class can be accessed only from itself or its child class, a non child class can’t consume them. Type can’t be declared as protected also. It applies only to members.
3.Internal:Members and types that are declared as internal are also accessible only within the project both for child and non child. The default scope for any type in C# is internal only.
4.Protected Internal:Members declared as protected internal enjoy dual scope i.e with in the project they behave as internal providing access to everyone in the project, outside the project they change to protected and still provide access to their corresponding child classes.
Types are also declared as protected internal only.
5.Public:A type or member of a type if declared as public will be global in scope which can be accessed from anywhere.

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is global asax in c#?

524


Enlist some of the properties of a thread class?

513


What is the use of generics in c#?

468


For read-only operation which property you have to designated?

557


What is meant by collections in c#?

452






What is difference between an reference type and value type in C#?

566


Do loops c#?

502


How many bytes is an int c#?

496


Is collection a data structure?

548


Explain what are the steps for creating clr trigger?

469


What is the interface in c#?

514


Is vs as c#?

514


What is a property in c#?

474


what class is underneath the sortedlist class?

553


Are value types sealed?

513