Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/Scope-modifiers/C-sharp/scope-modifiers-1.cs
Normal file
18
Task/Scope-modifiers/C-sharp/scope-modifiers-1.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
public //visible to anything.
|
||||
protected //visible to current class and to derived classes.
|
||||
internal //visible to anything inside the same assembly (.dll/.exe).
|
||||
protected internal //visible to anything inside the same assembly and also to derived classes outside the assembly.
|
||||
private //visible only to the current class.
|
||||
//C# 7.2 adds:
|
||||
private protected //visible to current class and to derived classes inside the same assembly.
|
||||
|
||||
// | | subclass | other class || subclass | other class
|
||||
//Modifier | class | in same assembly | in same assembly || outside assembly | outside assembly
|
||||
//-------------------------------------------------------------------------------------------------------
|
||||
//public | Yes | Yes | Yes || Yes | Yes
|
||||
//protected internal | Yes | Yes | Yes || Yes | No
|
||||
//protected | Yes | Yes | No || Yes | No
|
||||
//internal | Yes | Yes | Yes || No | No
|
||||
//private | Yes | No | No || No | No
|
||||
// C# 7.2:
|
||||
//private protected | Yes | Yes | No || No | No
|
||||
21
Task/Scope-modifiers/C-sharp/scope-modifiers-2.cs
Normal file
21
Task/Scope-modifiers/C-sharp/scope-modifiers-2.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
public interface IPrinter
|
||||
{
|
||||
void Print();
|
||||
}
|
||||
|
||||
public class IntPrinter : IPrinter
|
||||
{
|
||||
void IPrinter.Print() { // explicit implementation
|
||||
Console.WriteLine(123);
|
||||
}
|
||||
|
||||
public static void Main() {
|
||||
//====Error====
|
||||
IntPrinter p = new IntPrinter();
|
||||
p.Print();
|
||||
|
||||
//====Valid====
|
||||
IPrinter p = new IntPrinter();
|
||||
p.Print();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue