
接口定义属性、方法和事件,它们是接口的成员。接口仅包含成员的声明。
C# 中的一些接口类型包括。
IEnumerable – 所有通用集合的基本接口。
IList > – 由数组和列表类型实现的通用接口。
IDictionary – 字典集合。
IEnumerable 是一个接口,定义了单个方法 GetEnumerator,该方法返回 IEnumerator 接口。
这适用于对实现 IEnumerable 的集合的只读访问,该集合可与 foreach 语句一起使用。
这适用于对集合的只读访问。 p>
下面展示了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 methodpublic bool MoveNext() { throw new NotImplementedException();}// IEnumertor methodpublic void Reset() { throw new NotImplementedException();}
以上就是C# 接口类型的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1435558.html
微信扫一扫
支付宝扫一扫