13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 17 Classes(§14.5.4), instance members must be accessed through instances, and static members must be accessed throughtypes. end example]17.2.6 Nested typesA type declared within a class or struct is called a nested type. A type that is declared within a compilation unitor namespace is called a non-nested type. [Example: In the following example:using System;class A{class B{static void F() {Console.WriteLine("A.B.F");}}}class B is a nested type because it is declared within class A, and class A is a non-nested type because it isdeclared within a compilation unit. end example]17.2.6.1 Fully qualified nameThe fully qualified name (§10.8.1) for a nested type is S.N where S is the fully qualified name of the type inwhich type N is declared.17.2.6.2 Declared accessibilityNon-nested types can have public or internal declared accessibility and they have internal declared accessibilityby default. Nested types can have these forms of declared accessibility too, plus one or more additional forms ofdeclared accessibility, depending on whether the containing type is a class or struct:• A nested type that is declared in a class can have any of five forms of declared accessibility (public, protectedinternal, protected, internal, or private) and, like other class members, defaults to private declaredaccessibility.• A nested type that is declared in a struct can have any of three forms of declared accessibility (public,internal, or private) and, like other struct members, defaults to private declared accessibility.[Example: The examplepublic class List{// Private data structureprivate class Node{public object Data;public Node Next;public Node(object data, Node next) {this.Data = data;this.Next = next;}}private Node first = null;private Node last = null;// Public interfacepublic void AddToFront(object o) {…}public void AddToBack(object o) {…}public object RemoveFromFront() {…}public object AddToFront() {…}public int Count { get {…} }}declares a private nested class Node. end example]215

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

Saved successfully!

Ooh no, something went wrong!