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

C# LANGUAGE SPECIFICATION

1class Base<U>: I<U>

2{

3void I<U>.F() {…}

4}

5

class Derived<U, V>: Base<U>, I<V> // Ok

6

{

7void I<V>.F() {…}

8}

9This code is valid even though Derived<U, V> implements both I<U> and I<V>. The code

10I<int> x = new X<int,int>();

11x.F();

12invokes the method in Derived, since Derived<int, int> effectively re-implements I<int> (§20.4.4).

13end example]

1426.3.2 Explicit interface member implementations

15Explicit interface member implementations work with constructed interface types in essentially the same

16way as with simple interface types. As usual, an explicit interface member implementation shall be qualified

17by an interface-type indicating which interface is being implemented. This type can be a simple interface or

18a constructed interface [Example:

19interface IList<ElementType>

20{

21ElementType[] GetElements();

22}

23interface IDictionary<KeyType,ElementType>

24{

25

ElementType this[KeyType key] { get; }

26void Add(KeyType key, ElementType value);

27}

28class List<ElementType>: IList<ElementType>, IDictionary<int,ElementType>

29{

30

ElementType[] IList<ElementType>.GetElements() {…}

31

// Return the element at index

32

ElementType IDictionary<int,ElementType>.this[int index] {…}

33

// Add value at the index

34

void IDictionary<int,ElementType>.Add(int index, ElementType value)

35

{…}

36}

37end example]

3826.4 Generic delegate declarations

39[Note: A delegate declaration (§22.1), can optionally define type parameters and their associated constraints:

40delegate-declaration:

41

attributesopt delegate-modifiersopt

delegate return-type identifier type-parameter-listopt

42

( formal-parameter-listopt

) type-parameter-constraints-clausesopt ;

43end note]

44Generic delegate declarations follow the same rules as non-generic delegate declarations, except where

45noted below. Each type parameter in a generic delegate declaration defines a name in a special declaration

46space (§10.3) that is associated with that delegate declaration. The scope (§10.7) of a type parameter in a

47delegate declaration includes the return-type, formal-parameter-list, and type-parameter-constraints-

48clauses.

49Like other generic type declarations, type arguments shall be given to form a constructed delegate type. The

50parameter types and return type of a constructed delegate type are formed by substituting, for each type

51parameter in the delegate declaration, the corresponding type argument of the constructed delegate type. The

406

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