difference between keyword internal and protected?

Answer Posted / g2

protected :
This tells that the member is accessible to the derived
class and, in case, the class is a partial class then the
member is accessible to all the other partial classes to
this class. As you can access a protected member declared
in a code behind, you can access it in its respective .aspx
page also. If the member is in a class which is further
derived, it (the member) is available to the derived class
also.

internal :
This tells that the member is accessible any where in the
current assembly or the namespace. It never means that it
has larger scope than the protected. There can be derived
class of a class in other namespaces also. Then the member
with 'protected' will be accessible there but not a member
with 'internal' identifier.

'protected internal' or 'internal protected' :
This combination of identifier is a hybrid of both
protected and internal. But it does not enlarge the
accessibility but shrinks the accessibility instead. It
makes the member accessible to the "DERIVED CLASSES WITHIN
THE CURRENT ASSEMBLY OR NAMESPACE".

Is This Answer Correct ?    9 Yes 13 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is thread and explain states of a thread in c#?

636


Should I make my destructor virtual?

781


What are annotations in c#?

683


Can I define my own exceptions?

640


What is the diff between System.String and System.Text.StringBuilder classes?

721






What is unmannaged code and will CLR handle this kind of code or not .

763


What does immutable mean in c#?

686


How do I unload an application domain?

685


What is boxing & unboxing?

755


What is private variable?

652


What are the 3 logical operators?

726


What is parsing? How to parse a date time string?

721


What is sql transaction in c#?

651


How to do and Apply Themes to Datagrid,Lable,Textbox,etc., in C#.NET 2005 Windows Application? (like who we will do themes in ASP.NET using .CSS and .SKIN files). Urgent!!

1856


How do you implement thread synchronization (object.wait, notify,and criticalsection) in c#?

793