V.J.
V.J.

Reputation: 928

Object Oriented Programming Basic Concept(C#)

As We know

Default Modifier of

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?

Upvotes: 2

Views: 1735

Answers (5)

Henk Holterman
Henk Holterman

Reputation: 273244

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.

Upvotes: 2

Azodious
Azodious

Reputation: 13872

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.

Upvotes: 0

bitbonk
bitbonk

Reputation: 49619

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.

Upvotes: 2

Aristos
Aristos

Reputation: 66641

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

Upvotes: 0

LuigiEdlCarno
LuigiEdlCarno

Reputation: 2415

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

Upvotes: 0

Related Questions