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.

<strong>C#</strong> LANGUAGE SPECIFICATIONThe exampleusing System;class Point{public double x, y;public Point(double x, double y) {this.x = x;this.y = y;}~Point() {Console.WriteLine("Destructed {0}", this);}public override string ToString() {return string.Format("({0}, {1})", x, y);}}shows a Point class with a destructor.8.7.10 Static constructorsA static constructor is a member that implements the actions required to initialize a class. Static constructorscannot have parameters, they cannot have accessibility modifiers, and they cannot be called explicitly. Thestatic constructor for a class is called automatically.The exampleusing Personnel.Data;class Employee{private static DataSet ds;}static Employee() {ds = new DataSet(…);}public string Name;public decimal Salary;…shows an Employee class with a static constructor that initializes a static field.8.7.11 InheritanceClasses support single inheritance, and the type object is the ultimate base class for all classes.The classes shown in earlier examples all implicitly derive from object. The exampleusing System;class A{public void F() { Console.WriteLine("A.F"); }}shows a class A that implicitly derives from object. The exampleclass B: A{public void G() { Console.WriteLine("B.G"); }}class Test{static void Main() {B b = new B();b.F();// Inherited from Ab.G();// Introduced in B40

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

Saved successfully!

Ooh no, something went wrong!