Scope modifiers: Difference between revisions

Content deleted Content added
Cbrt74088 (talk | contribs)
m C# minor edit
Cbrt74088 (talk | contribs)
C# made table clearer
Line 300: Line 300:
protected internal //visible to anything inside the same assembly and also to derived classes outside the assembly.
protected internal //visible to anything inside the same assembly and also to derived classes outside the assembly.
private //visible only to the current class.
private //visible only to the current class.
C# 7.2 adds:
//C# 7.2 adds:
private protected //visible to current class and to derived classes inside the same assembly.
private protected //visible to current class and to derived classes inside the same assembly.


//Modifier | Class | Assembly | Subclass | World
// | | subclass | other class || subclass | other class
//Modifier | class | in same assembly | in same assembly || outside assembly | outside assembly
//--------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
//public | Y | Y | Y | Y
//protected internal | Y | Y | Y | N
//public | Yes | Yes | Yes || Yes | Yes
//protected | Y | N | Y | N
//protected internal | Yes | Yes | Yes || Yes | No
//internal | Y | Y | N | N
//protected | Yes | Yes | No || Yes | No
//private | Y | N | N | N
//internal | Yes | Yes | Yes || No | No
//private | Yes | No | No || No | No
// C# 7.2:
// C# 7.2:
//private protected | Y | intersection | N</lang>
//private protected | Yes | Yes | No || No | No</lang>
If no modifier is specified, it defaults to the most restrictive one.<br/>
If no modifier is specified, it defaults to the most restrictive one.<br/>
In case of top-level classes/structs/interfaces/enums this means internal, otherwise it means private.
In case of top-level classes/structs/interfaces/enums this means internal, otherwise it means private.