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 SPECIFICATION}}set {MyField = value;}public int this[int index] {get {return 0;}set {Console.WriteLine("this[{0}] = {1}", index, value);}}public event EventHandler MyEvent;public static MyClass operator+(MyClass a, MyClass b) {return new MyClass(a.MyField + b.MyField);}internal class MyNestedClass{}shows a class that contains each kind of member. The exampleclass Test{static void Main() {// Instance constructor usageMyClass a = new MyClass();MyClass b = new MyClass(123);// Constant usageConsole.WriteLine("MyConst = {0}", MyClass.MyConst);// Field usagea.MyField++;Console.WriteLine("a.MyField = {0}", a.MyField);// Method usagea.MyMethod();// Property usagea.MyProperty++;Console.WriteLine("a.MyProperty = {0}", a.MyProperty);// Indexer usagea[3] = a[1] = a[2];Console.WriteLine("a[3] = {0}", a[3]);// Event usagea.MyEvent += new EventHandler(MyHandler);// Overloaded operator usageMyClass c = a + b;}static void MyHandler(object sender, EventArgs e) {Console.WriteLine("Test.MyHandler");}internal class MyNestedClass{}}shows uses of these members.8.7.1 ConstantsA constant is a class member that represents a constant value: a value that can be computed at compile-time.Constants are permitted to depend on other constants within the same program as long as there are nocircular dependencies. The rules governing constant expressions are defined in §14.15. The example32

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

Saved successfully!

Ooh no, something went wrong!