2

As We know

Default Modifier of

  • Class
  • Struct
  • Delegate
  • Interface
  • Enum

is Internal.

  1. Enum & Interface members by default are public.

  2. And Class, Struct , Delegate members by default are private.

  3. Non-derived class of same class-library can have access to public and internal class (and public, internal, protected internal-members).

  4. Non-derived class of different class-library can have access to public class (public members only).

  5. Derived class of different class-library can have access to public class (public, protected, protected-internal members).

Now I want to understand the core concept that why is so that...

Protected members are having more scope than internal?

5 Answers 5

2

From the docs:

protected

The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class.

internal

The type or member can be accessed by any code in the same assembly, but not from another assembly.

protected internal

The type or member can be accessed by any code in the assembly in which it is declared, or from within a derived class in another assembly. Access from another assembly must take place within a class declaration that derives from the class in which the protected internal element is declared, and it must take place through an instance of the derived class type.

Sign up to request clarification or add additional context in comments.

3 Comments

Protected should be edited as: The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class. That can be the same or different Assembly.
We are specifying assembly access level in protected-internal. Then why not in protected.? :(
Because it is necessary there to fully formulate all rules. It is not necessary for protected and would be redundant information. While this is implicit (it doesn't mention any assembly restrictions because there are none) I think it'd be clearer to explictly mention it since it is mentionen for the public modifier too: The type or member can be accessed by any other code in the same assembly or another assembly that references it.
2

4) Non-derived class of different class-library can have access to public class (public, protected, protected-internal members).

This is not correct.

4) Non-derived class of different class-library can have access to public class (public members only).

And that means that the actual question is also debatable:

why is so that... Protected members are having more scope than internal?

protected and internal have different scopes. Which one is 'larger' is difficult to say. Comparing them in this way is simply not useful.

1 Comment

yes u r right. i have edited. protected and internal have different scopes. but internal is limited to same assembly but protected can be used in different assembly.
0

Protected simply means, that this member or method can not be overridden in a derieving class. Otherwise they behave like public members/methods.

Comments

0

Internal members are not declare for export, so thats why they can not been seen out side the module, the dll of them.

Comments

0

why is so that ... Protected members are having more scope than internal?

Because you can have a protected member accessible across assemblies but that's not true with internal.

internal Internal members are accessible only within files in the same assembly. its scope is limited to assembly only.

protected can be accessible outside assembly. A protected member is accessible from within the class in which it is declared, and from within any class derived from the class that declared this member. This derived class can be outside assembly.

hence it has more scope than internal modifier.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.