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 xml serialization and deserialization in c#?

483


What do you mean by synchronous and asynchronous operations?

474


How to declare a property in a class?

549


What is the default value of decimal in c#?

494


What is cshtml?

523






Is c# or c++ better for games?

466


What is lastindexof c#?

484


What does int32 mean in c#?

469


Explain nullable types in c#?

541


How can I get around scope problems in a try/catch?

477


List some Advantages of switch-case over if else?

497


Differentiate between dataset and datareader?

526


What is dictionary collection in c#?

497


Can abstract class have parameterized constructor?

499


Between windows authentication and sql server authentication, which one is trusted and which one is untrusted?

486