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 生日广州男生祝福语简短