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 interface IComparable class ListEntry: ICloneable, IComparable 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 interface ITextBox: IControl class TextBox: ITextBox 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.
|