September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
13
Task/Scope-modifiers/C-sharp/scope-modifiers-1.cs
Normal file
13
Task/Scope-modifiers/C-sharp/scope-modifiers-1.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
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.
|
||||
|
||||
//Modifier | Class | Assembly | Subclass | World
|
||||
//--------------------------------------------------------
|
||||
//public | Y | Y | Y | Y
|
||||
//protected internal | Y | Y | Y | N
|
||||
//protected | Y | N | Y | N
|
||||
//internal | Y | Y | N | N
|
||||
//private | Y | N | N | N
|
||||
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