Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
C-sharp language specification.2004.pdf
Скачиваний:
14
Добавлен:
23.08.2013
Размер:
2.55 Mб
Скачать

C# LANGUAGE SPECIFICATION

1Interface implementations are discussed further in §20.4.

217.1.3 Class body

3The class-body of a class defines the members of that class.

4class-body:

5

{ class-member-declarationsopt }

617.1.4 Partial declarations

7The modifier partial is used when defining a class, struct, or interface type in multiple parts. Like get

8and set in property accessors, partial is not a keyword. partial shall appear immediately before one of

9the keywords class, struct, or interface.

10Each part of a partial type declaration shall include a partial modifier and shall be declared in the same

11namespace or containing type as the other parts. The partial modifier indicates that additional parts of the

12type declaration might exist elsewhere, but the existence of such additional parts is not a requirement; it is

13valid for the only declaration of a type to include the partial modifier.

14All parts of a partial type shall be compiled together such that the parts can be merged at compile-time.

15Partial types specifically do not allow already compiled types to be extended.

16Nested types can be declared in multiple parts by using the partial modifier. Typically, the containing

17type is declared using partial as well, and each part of the nested type is declared in a different part of the

18containing type.

19[Example: The following partial class is implemented in two parts, which reside in different source files. The

20first part is machine generated by a database mapping tool while the second part is manually authored:

21public partial class Customer

22{

23

private int id;

24

private string name;

25

private string address;

26

private List<Order> orders;

27

public Customer() {

28

...

29}

30}

31public partial class Customer

32{

33

public void SubmitOrder(Order orderSubmitted) {

34

orders.Add(orderSubmitted);

35

}

36

public bool HasOutstandingOrders() {

37

return orders.Count > 0;

38}

39}

40When the two parts above are compiled together, the resulting code behaves as if the class had been written

41as a single unit, as follows:

42public class Customer

43{

44

private int id;

45

private string name;

46

private string address;

47

private List<Order> orders;

48

public Customer() {

49

...

50

}

260

Соседние файлы в предмете Электротехника