C#接口类型
接口定义属性,方法和事件,它们是接口的成员。接口仅包含成员的声明。
C#中的某些接口类型包括。
IEnumerable-所有通用集合的基本接口。
IList-由数组和列表类型实现的通用接口。
IDictionary-词典集合。
IEnumerable是定义单个方法GetEnumerator的接口,该方法返回IEnumerator接口。
这适用于对实现IEnumerable可以与foreach语句一起使用的集合的只读访问。
下面显示了IEnumerable接口的实现。
示例
class Demo : IEnumerable, IEnumerator {
// IEnumerable method GetEnumerator() IEnumerator IEnumerable.GetEnumerator() {
throw new NotImplementedException();
}
public object Current {
get { throw new NotImplementedException(); }
}
//IEnumertor方法
public bool MoveNext() {
throw new NotImplementedException();
}
//IEnumertor方法
public void Reset() {
throw new NotImplementedException();
}
}在上面可以看到IEnumerator的两种方法。
// IEnumerator method
public bool MoveNext() {
throw new NotImplementedException();
}
//IEnumertor方法
public void Reset() {
throw new NotImplementedException();
}热门推荐
10 圣诞祝福语简短小学
11 祖国七十华诞简短祝福语
12 老师送的祝福语简短
13 生日祝福语大全女生简短
14 祝女性生日祝福语简短
15 牛年女神节祝福语简短
16 情人表白祝福语简短大气
17 老公开业祝福语简短
18 官宣新年祝福语简短