C# 介面型別
介面定義屬性、方法和事件,它們是介面的成員。介面只包含成員的宣告。
C# 中的一些介面型別包括:
IEnumerable − 所有泛型集合的基本介面。
IList − 陣列和列表型別實現的一個泛型介面。
IDictionary − 一個字典集合。
IEnumerable 是一個介面,定義了一個返回 IEnumerator 介面的單一方法 GetEnumerator。
這適用於對實現 IEnumerable 的集合的只讀訪問,可以用在 foreach 語句中。
以下程式碼演示了 IEnumerable 介面的實現:
示例
class Demo : IEnumerable, IEnumerator {
// IEnumerable method GetEnumerator()
IEnumerator IEnumerable.GetEnumerator() {
throw new NotImplementedException();
}
public object Current {
get { throw new NotImplementedException(); }
}
// IEnumertor method
public bool MoveNext() {
throw new NotImplementedException();
}
// IEnumertor method
public void Reset() {
throw new NotImplementedException();
}
}以上您可以看到 IEnumerator 的兩種方法。
// IEnumerator method
public bool MoveNext() {
throw new NotImplementedException();
}
// IEnumertor method
public void Reset() {
throw new NotImplementedException();
}
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP