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 好听的元旦简短祝福语