logo
CSharp_Prog_Guide

Результат

CoOrds #1 at (0,0)

CoOrds #2 at (5,3)

Example 2

In this example, the class Person does not have any constructors, in which case, a default constructor is automatically provided and the fields are initialized to their default values.

public class Person

{

public int age;

public string name;

}

class TestPerson

{

static void Main()

{

Person p = new Person();

System.Console.Write("Name: {0}, Age: {1}", p.name, p.age);

}

}

Output

Name: , Age: 0

Notice that the default value of age is 0 and the default value of name is null.

Example 3

The following example demonstrates using the base class initializer. The Circle class is derived from the general class Shape, and the Cylinder class is derived from the Circle class. The constructor on each derived class is using its base class initializer.