C# interface type

PHPz
PHPzforward
2023-09-18 17:17:021522browse

C# 接口类型

Interface defines properties, methods and events, which are members of the interface. An interface only contains declarations of members.

Some interface types in C# include.

  • IEnumerable - The basic interface for all common collections.

  • #IList > - Generic interface implemented by array and list types.

  • IDictionary - Collection of dictionaries.

  • IEnumerable is an interface that defines a single method GetEnumerator, which returns the IEnumerator interface.

    This applies to read-only access to collections that implement IEnumerable, which can be used with a foreach statement.

    This applies to read-only access to the collection. p>

    The following shows the implementation of the IEnumerable interface.

    Example

    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();
       }
    }

    Above you can see the two methods of IEnumerator.

    // IEnumerator method
    public bool MoveNext() {
       throw new NotImplementedException();
    }
    // IEnumertor method
    public void Reset() {
       throw new NotImplementedException();
    }

    The above is the detailed content of C# interface type. For more information, please follow other related articles on the PHP Chinese website!

    Statement:
    This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete