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

How to rotate an Image in C#?

578


What is array and arraylist?

536


What is a scope in c#?

470


What does .length do in c#?

523


Why do I get an error (cs1006) when trying to declare a method without specifying a return type?

541






Is it possible to force garbage collector to run?

480


What are cshtml files?

486


What is difference between const and static in c#?

492


What is autopostback in c#?

472


Why dataset is used in c#?

509


What is the difference between list and arraylist c#?

518


What is class sortedlist underneath?

567


What is Global Assembly Cache (GAC) and what is the purpose of it? (How to make an assembly to public? Steps) How more than one version of an assembly can keep in same place?

561


How do I make a dll in c#?

500


Why do we use overloading in c#?

476