首页  >  文章  >  后端开发  >  C# 接口类型

C# 接口类型

PHPz
PHPz转载
2023-09-18 17:17:021396浏览

C# 接口类型

接口定义属性、方法和事件,它们是接口的成员。接口仅包含成员的声明。

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 method
    public bool MoveNext() {
       throw new NotImplementedException();
    }
    // IEnumertor method
    public void Reset() {
       throw new NotImplementedException();
    }

    以上是C# 接口类型的详细内容。更多信息请关注PHP中文网其他相关文章!

    声明:
    本文转载于:tutorialspoint.com。如有侵权,请联系admin@php.cn删除