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

Chapter 10 Basic concepts

1public A H() {…}

2}

3the H method in B results in a compile-time error because the return type A is not at least as accessible as the

4method. end example]

510.6 Signatures and overloading

6Methods, instance constructors, indexers, and operators are characterized by their signatures:

7The signature of a method consists of the name of the method, the number of type parameters, and the

8type and kind (value, reference, or output) of each of its formal parameters, considered in the order left

9to right. The signature of a method specifically does not include the return type, parameter names or

10type parameter names, nor does it include the params modifier that can be specified for the right-most

11parameter. When a parameter type includes a type parameter of the method, the ordinal position of the

12type parameter is used for type equivalence, not the name of the type parameter.

13The signature of an instance constructor consists of the type and kind (value, reference, or output) of

14each of its formal parameters, considered in the order left to right. The signature of an instance

15constructor specifically does not include the parameter names or the params modifier that can be

16specified for the right-most parameter.

17The signature of an indexer consists of the type of each of its formal parameters, considered in the order

18left to right. The signature of an indexer specifically does not include the element type or parameter

19names, nor does it include the params modifier that can be specified for the right-most parameter.

20The signature of an operator consists of the name of the operator and the type of each of its formal

21parameters, considered in the order left to right. The signature of an operator specifically does not

22include the result type or parameter names.

23Signatures are the enabling mechanism for overloading of members in classes, structs, and interfaces:

24Overloading of methods permits a class, struct, or interface to declare multiple methods with the same

25name, provided their signatures are unique within that class, struct, or interface.

26Overloading of instance constructors permits a class or struct to declare multiple instance constructors,

27provided their signatures are unique within that class or struct.

28Overloading of indexers permits a class, struct, or interface to declare multiple indexers, provided their

29signatures are unique within that class, struct, or interface.

30Overloading of operators permits a class or struct to declare multiple operators with the same name,

31provided their signatures are unique within that class or struct.

32Although out and ref parameter modifiers are considered part of a signature, members declared in a single

33type cannot differ in signature solely by ref and out. A compile-time error occurs if two members are

34declared in the same type with signatures that would be the same if all parameters in both methods with out

35modifiers were changed to ref modifiers. For other purposes of signature matching (e.g., hiding or

36overriding), ref and out are considered part of the signature and do not match each other. [Note: This

37restriction is to allow C# programs to be easily translated to run on the Common Language Infrastructure

38(CLI), which does not provide a way to define methods that differ solely in ref and out. end note]

39[Example: The following example shows a set of overloaded method declarations along with their

40signatures.

41interface ITest

42{

43

void F();

// F()

 

44

void F(int x);

// F(int)

 

45

void F(ref int x);

// F(ref int)

 

46

void F(out int x);

// F(out int)

error

93

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