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