13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>C#</strong> LANGUAGE SPECIFICATION17.2.6.3 HidingA nested type may hide (§10.7.1.1) a base member. The new modifier is permitted on nested type declarations sothat hiding can be expressed explicitly. [Example: The exampleusing System;class Base{public static void M() {Console.WriteLine("Base.M");}}class Derived: Base{new public class M{public static void F() {Console.WriteLine("Derived.M.F");}}}class Test{static void Main() {Derived.M.F();}}shows a nested class M that hides the method M defined in Base. end example]17.2.6.4 this accessA nested type and its containing type do not have a special relationship with regard to this-access (§14.5.7).Specifically, this within a nested type cannot be used to refer to instance members of the containing type. Incases where a nested type needs access to the instance members of its containing type, access can be provided byproviding the this for the instance of the containing type as a constructor argument for the nested type.[Example: The following exampleusing System;class C{int i = 123;public void F() {Nested n = new Nested(this);n.G();}public class Nested{C this_c;public Nested(C c) {this_c = c;}public void G() {Console.WriteLine(this_c.i);}}}class Test{static void Main() {C c = new C();c.F();}}216

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!