Студопедия
Случайная страница | ТОМ-1 | ТОМ-2 | ТОМ-3
АрхитектураБиологияГеографияДругоеИностранные языки
ИнформатикаИсторияКультураЛитератураМатематика
МедицинаМеханикаОбразованиеОхрана трудаПедагогика
ПолитикаПравоПрограммированиеПсихологияРелигия
СоциологияСпортСтроительствоФизикаФилософия
ФинансыХимияЭкологияЭкономикаЭлектроника

Fully qualified interface member names

Static constructors | The MoveNext method | Implementation example | Value semantics | Boxing and unboxing | Meaning of this | Database integer type | Database boolean type | Array initializers | Interface members |


Читайте также:
  1. A day to remember
  2. A day to remember
  3. A. Read the text and explain carefully whether you still share the common myths about the modern male.
  4. Access to private and protected members of the containing type
  5. Active vocabulary to remember
  6. Active vocabulary to remember
  7. Air interface

An interface member is sometimes referred to by its fully qualified name. The fully qualified name of an interface member consists of the name of the interface in which the member is declared, followed by a dot, followed by the name of the member. The fully qualified name of a member references the interface in which the member is declared. For example, given the declarations

interface IControl
{
void Paint();
}

interface ITextBox: IControl
{
void SetText(string text);
}

the fully qualified name of Paint is IControl.Paint and the fully qualified name of SetText is ITextBox.SetText.

In the example above, it is not possible to refer to Paint as ITextBox.Paint.

When an interface is part of a namespace, the fully qualified name of an interface member includes the namespace name. For example

namespace System
{
public interface ICloneable
{
object Clone();
}
}

Here, the fully qualified name of the Clone method is System.ICloneable.Clone.

Interface implementations

Interfaces may be implemented by classes and structs. To indicate that a class or struct directly implements an interface, the interface identifier is included in the base class list of the class or struct. For example:

interface ICloneable
{
object Clone();
}

interface IComparable
{
int CompareTo(object other);
}

class ListEntry: ICloneable, IComparable
{
public object Clone() {...}

public int CompareTo(object other) {...}
}

A class or struct that directly implements an interface also directly implements all of the interface’s base interfaces implicitly. This is true even if the class or struct doesn’t explicitly list all base interfaces in the base class list. For example:

interface IControl
{
void Paint();
}

interface ITextBox: IControl
{
void SetText(string text);
}

class TextBox: ITextBox
{
public void Paint() {...}

public void SetText(string text) {...}
}

Here, class TextBox implements both IControl and ITextBox.

When a class C directly implements an interface, all classes derived from C also implement the interface implicitly. The base interfaces specified in a class declaration can be constructed interface types (§4.4). A base interface cannot be a type parameter on its own, though it can involve the type parameters that are in scope. The following code illustrates how a class can implement and extend constructed types:

class C<U,V> {}

interface I1<V> {}

class D: C<string,int>, I1<string> {}

class E<T>: C<int,T>, I1<T> {}

The base interfaces of a generic class declaration must satisfy the uniqueness rule described in §13.4.2.


Дата добавления: 2015-11-16; просмотров: 64 | Нарушение авторских прав


<== предыдущая страница | следующая страница ==>
Interface member access| Explicit interface member implementations

mybiblioteka.su - 2015-2024 год. (0.006 сек.)