Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does Protected Internal mean in .Net [duplicate]

Tags:

c#

.net

oop

Protected Means, we can access this member only in a deriving class, and internal means we can access this member in any type in the same assembly using a object. So can I consider a Protected Internal member as a public member in the same assembly. and as a protected member in the different assembly.

EDIT:

namespace pracConsole     { class Class1 {     protected internal int val;     public int hello()     {         Console.WriteLine("This is method pracConsole.hello");         Console.ReadLine();         return 1;      } } class program {     static void Main(string[] args)     {         Class1 _class1 = new Class1();         _class1.val = 3;         _class1.hello();         Console.ReadLine();     } } 

}

See I am able to access, protected internal in a non deriving class...so its working as public in same assembly..what do you say.

like image 397
Vaibhav Jain Avatar asked Apr 16 '10 06:04

Vaibhav Jain


People also ask

What does protected internal mean?

protected internal: The type or member can be accessed by any code in the assembly in which it's declared, or from within a derived class in another assembly. private protected: The type or member can be accessed by types derived from the class that are declared within its containing assembly.

What is protected internal in C#?

The protected internal keyword combination is a member access modifier. A protected internal member is accessible from the current assembly or from types that are derived from the containing class. For a comparison of protected internal with the other access modifiers, see Accessibility Levels.

What is internal keyword in .NET framework?

The internal keyword is an access modifier for types and type members. This page covers internal access. The internal keyword is also part of the protected internal access modifier. Internal types or members are accessible only within files in the same assembly, as in this example: C# Copy.

What is public/private and protected in C#?

public - can be access by anyone anywhere. private - can only be accessed from with in the class it is a part of. protected - can only be accessed from with in the class or any object that inherits off of the class.


1 Answers

It's a confusing one.

protected means "only this class and derived classes".

internal means "only classes in this assembly".

protected internal means "protected OR internal" (any class in the same assembly, or any derived class - even if it is in a different assembly).

i.e. it does not mean "protected AND internal" (only derived classes within the same assembly).

like image 98
Jason Williams Avatar answered Sep 29 '22 06:09

Jason Williams