Saturday 30 March 2019

Types of Interface in C#

Interfaces define properties, methods, and events, which are the members of the interface.Interfaces contain only the declaration of the members.
Some of the interface types in C# include.
  • IEnumerable − Base interface for all generic collections.
  • IList − A generic interface implemented by the arrays and the list type.
  • IDictionary − A dictionary collection.
IEnumerable is an interface defining a single method GetEnumerator that returns an IEnumerator interface.
This works for readonly access to a collection that implements that IEnumerable can be used with a foreach statement.
The following shows the implementation of IEnumerable interface.
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();
}

No comments:

Post a Comment

C# LINQ Joins With SQL

There are  Different Types of SQL Joins  which are used to query data from more than one database tables. In this article, you will learn a...