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 8 <strong>Language</strong> Overviewlock statements static void Main() {A a = …;lock(a) {a.P = a.P + 1;}}using statements static void Main() {using (Resource r = new Resource()) {r.F();}}8.7 ClassesClass declarations define new reference types. A class can inherit from another class, and can implementinterfaces.Class members can include constants, fields, methods, properties, events, indexers, operators, instanceconstructors, destructors, static constructors, and nested type declarations. Each member has an associatedaccessibility (§10.5), which controls the regions of program text that are able to access the member. Thereare five possible forms of accessibility. These are summarized in the table below.FormpublicprotectedinternalprotectedinternalprivateIntuitive meaningAccess not limitedAccess limited to the containing class or types derived from the containing classAccess limited to this programAccess limited to this program or types derived from the containing classAccess limited to the containing typeThe exampleusing System;class MyClass{public MyClass() {Console.WriteLine("Instance constructor");}public MyClass(int value) {MyField = value;Console.WriteLine("Instance constructor");}~MyClass() {Console.WriteLine("Destructor");}public const int MyConst = 12;public int MyField = 34;public void MyMethod(){Console.WriteLine("MyClass.MyMethod");}public int MyProperty {get {return MyField;}31

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

Saved successfully!

Ooh no, something went wrong!