This is very common for beginners to get fuzzy with these words in their head. These are all alike and seem to be used for the same purpose. Well, let us see how all these are different.
Do they have the same purpose? In some ways, they do have the same purpose, but there are some differences also and we are going through the differences and similarities here in this article below.
Let us start with the types that start with an "I". They represent the interface, while their implementation are the classes that do not start with "I".
| Interface | Implementation |
| IList | List |
| IQueryable | Queryable |
| IEnumerator | |
| IEnumarable | Enumerable |
With the exception of the IQueryable / Queryable which derives from LINQ, they all derive from C# collections, along with many other types.
What is an interface?
An interface contains the signature of methods, properties, events, and indexers that are going to have their behavior implemented in the classes that inherit from it.
Example of an interface and its implementation -
- interface ISample
- {
- void AnyMethod();
- }
- class Sample : ISample
- {
- // Interface member implementation:
- void AnyMethod()
- {
- // The method implementation.
- }
- static void Main()
- {
- // Declare an interface instance.
- ISample obj = new Sample();
- // Call the member.
- obj.AnyMethod();
- }
- }
Benefits of using Interfaces
You may feel that it is a waste of time to create interfaces but here is why it is important.
- Decoupling, reducing dependency from implementation classes;
- Readability, as an interface implements the signature of your code their name must make sense with their purpose;
- Maintainability, making it possible of having different implementations based on the same interface;
- Extensibility, being easier to extend classes with a different implementation based on the same contract.
IQueryable vs IEnumarable vs IEnumerator vs IList
Inherits from IEnumerable and has this signature -
- using System.Collections;
- using System.Linq.Expressions;
- namespace System.Linq
- {
- //
- // Summary:
- // Provides functionality to evaluate queries against a specific data source wherein
- // the type of the data is not specified.
- public interface IQueryable : IEnumerable
- {
- //
- // Summary:
- // Gets the type of the element(s) that are returned when the expression tree associated
- // with this instance of System.Linq.IQueryable is executed.
- //
- // Returns:
- // A System.Type that represents the type of the element(s) that are returned when
- // the expression tree associated with this object is executed.
- Type ElementType { get; }
- //
- // Summary:
- // Gets the expression tree that is associated with the instance of System.Linq.IQueryable.
- //
- // Returns:
- // The System.Linq.Expressions.Expression that is associated with this instance
- // of System.Linq.IQueryable.
- Expression Expression { get; }
- //
- // Summary:
- // Gets the query provider that is associated with this data source.
- //
- // Returns:
- // The System.Linq.IQueryProvider that is associated with this data source.
- IQueryProvider Provider { get; }
- }
- }
IEnumerable
Exposes the enumerator which supports a simple iteration over a collection of a specified type.
- namespace System.Collections.Generic
- {
- //
- // Summary:
- // Exposes the enumerator, which supports a simple iteration over a collection of
- // a specified type.
- //
- // Type parameters:
- // T:
- // The type of objects to enumerate.
- public interface IEnumerable<out T> : IEnumerable
- {
- //
- // Summary:
- // Returns an enumerator that iterates through the collection.
- //
- // Returns:
- // An enumerator that can be used to iterate through the collection.
- IEnumerator<T> GetEnumerator();
- }
- }
IEnumerator
Supports a simple iteration over a generic collection and does not have an implementation like the other interfaces. It is better used for iteration over generic collections, like when using a foreach statement.

e vPosted May 30, 2019, 4:10 PM
Very weak and supperficial. No explanations, just links to articles, which you do yourself. Waste of time!
Mahesh ChandPosted May 22, 2019, 7:02 PM
Thank you, Thiago.