logo
CSharp_Prog_Guide

Ограничения

Имеется несколько правил, которые необходимо выполнять при работе с определениями разделяемого класса:

----

Example 1

Description

In the following example, the fields and the constructor of the class, CoOrds, are declared in one partial class definition, and the member, PrintCoOrds, is declared in another partial class definition.

Code

public partial class CoOrds

{

private int x;

private int y;

public CoOrds(int x, int y)

{

this.x = x;

this.y = y;

}

}

public partial class CoOrds

{

public void PrintCoOrds()

{

System.Console.WriteLine("CoOrds: {0},{1}", x, y);

}

}

class TestCoOrds

{

static void Main()

{

CoOrds myCoOrds = new CoOrds(10, 15);

myCoOrds.PrintCoOrds();

}

}

Output

CoOrds: 10,15