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

C# LANGUAGE SPECIFICATION

1class C

2{

3

void Test(INumber n) {

 

4

n.Add(1);

// Error, both Add methods are applicable

5

n.Add(1.0);

// Ok, only IDouble.Add is applicable

6

((IInteger)n).Add(1);

// Ok, only IInteger.Add is a candidate

7

((IDouble)n).Add(1);

// Ok, only IDouble.Add is a candidate

8}

9}

10the invocation n.Add(1) is ambiguous because a method invocation (§14.5.5.1) requires all overloaded

11candidate methods to be declared in the same type. However, the invocation n.Add(1.0) is permitted

12because only IDouble.Add is applicable. When explicit casts are inserted, there is only one candidate

13method, and thus no ambiguity. end example]

14[Example: In the following code

15interface IBase

16{

17void F(int i);

18}

19interface ILeft: IBase

20{

21new void F(int i);

22}

23interface IRight: IBase

24{

25void G();

26}

27interface IDerived: ILeft, IRight {}

28class A

29{

30

void Test(IDerived d) {

 

31

d.F(1);

// Invokes ILeft.F

32

((IBase)d).F(1);

// Invokes IBase.F

33

((ILeft)d).F(1);

// Invokes ILeft.F

34

((IRight)d).F(1);

// Invokes IBase.F

35}

36}

37the IBase.F member is hidden by the ILeft.F member. The invocation d.F(1) thus selects ILeft.F,

38even though IBase.F appears to not be hidden in the access path that leads through IRight.

39The intuitive rule for hiding in multiple-inheritance interfaces is simply this: If a member is hidden in any

40access path, it is hidden in all access paths. Because the access path from IDerived to ILeft to IBase

41hides IBase.F, the member is also hidden in the access path from IDerived to IRight to IBase. end

42example]

4320.3 Fully qualified interface member names

44An interface member is sometimes referred to by a qualified interface member name. A qualified interface

45member name consists of a name identifying the interface in which the member is declared, followed by a

46dot, followed by the name of the member. [Example: Given the declarations

47interface IControl

48{

49void Paint();

50}

51interface ITextBox: IControl

52{

53void SetText(string text);

54}

340

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