Introduction
First let's see a small demonstration of both of these interfaces and then we will talk about the differences.
DEMO
Create a new console application and in the main method add the following.
static void Main(string[] args)
{
List<string> Month = new List<string>();
Month.Add("January");
Month.Add("February");
Month.Add("March");
Month.Add("April");
Month.Add("May");
Month.Add("June");
Month.Add("July");
Month.Add("August");
Month.Add("September");
Month.Add("October");
Month.Add("November");
Month.Add("December");
}
In our main method, we created a new list collection “Month” of type string. In this collection we added all the 12 months as items in this list.
Note: The List class is present in the System.Collections.Generic namespace.
Now let's create a very simple IEnumerable on this list.
//create IEnumerable of string
IEnumerable<string> iEnumerableOfString = (IEnumerable<string>)Month;
//If we want to retrieve all the items from this IEnumerable object, we can use a foreach loop.
foreach(string AllMonths in iEnumerableOfString)
{
Console.WriteLine(AllMonths);
}
Run the application.

We got the list of months.
Now let's see how to do the same, using an IEnumerator and then we will see the differences.
//Create IEnumerator of string.
IEnumerator<string> iEnumeratorOfString = Month.GetEnumerator();//to convert list into IEnumerator we can invoke the GetEnumerator method
//To retrieve all the items from the above IEnumerator object, we cannot use foreach loop instead of that we need to invoke MoveNext() Boolean method.
while(iEnumeratorOfString.MoveNext())
{
}
To display the items on the console window we need to invoke the Current property as in the following:
while(iEnumeratorOfString.MoveNext())
{
Console.WriteLine(iEnumeratorOfString.Current);
}
Run the application.

Similarities
Both of these interfaces help to loop through the collection.
So, now the next question is, what should I use?
As we know, both of these interfaces give the same result. But if you watch the syntax for IEnumerable, it is very simple.
foreach(string AllMonths in iEnumerableOfString)
{
Console.WriteLine(AllMonths);
}
But in the case of IEnumerator, we need to invoke the MoveNext method and to retrieve the current item, we need to invoke the current property.
Relation
The IEnumerable interface actually uses IEnumerator. The main reason to create an IEnumerable is to make the syntax shorter and simpler.
If you go to the definition of the IEnumerable<T> interface, you will see this interface has a method GetEnumerator() that returns an IEnumerator object back.








Anuja SarnaikPosted Dec 26, 2021, 11:03 PM
Pointed the correct difference with demo
farukh shaikhPosted Mar 28, 2020, 12:46 AM
Nice Bro!!!!
Shailesh BariaPosted Dec 8, 2018, 3:29 AM
Nice Explanation ...!!!
John StellonPosted Oct 9, 2018, 2:49 PM
You've shed so much light on a subject that seemed so difficult to understand for a novice but now seems so simple.
Lalit RaghavPosted Aug 14, 2018, 5:51 AM
NICE Article
Lalit RaghavPosted Aug 14, 2018, 5:50 AM
NICE Article
Gowthami BalakrishnanPosted Jan 2, 2018, 8:39 AM
Correct me if am wrong.
Gowthami BalakrishnanPosted Jan 2, 2018, 8:38 AM
In IEnumeratorMethodTwo, we have i.MoveNext(). So when this method called, the cursor position should be move from june to july. So in output, it shouldn't print june. Am i right.?\
karthik muthuPosted Sep 13, 2017, 2:02 AM
Perfect Explanation.. Thank you.
Mazhar PashaPosted May 16, 2017, 8:06 AM
Very nice article..good explanation..
Yogesh TripathiPosted May 11, 2017, 10:29 AM
Nice one....................................
Anil KumarPosted Mar 10, 2017, 5:34 AM
Good, Nice Explained Harpreet Singh
Naveen BishtPosted Jul 14, 2016, 2:39 AM
NICE
Vetri Chelvan IndrajithPosted Jun 25, 2016, 2:08 AM
Fantastic Article.. Keep it go..
Santhakumar MunuswamyPosted Oct 1, 2015, 10:12 PM
Good one
Bruno PétersonPosted Apr 25, 2015, 11:06 AM
I liked it. Thanks for sharing it!
Karthik Muthu KaruppanPosted Mar 20, 2015, 11:11 AM
good explanation
Tom MohanPosted Mar 19, 2015, 12:31 PM
Nice explanation
Harpreet SinghPosted Mar 19, 2015, 4:39 AM
Rajeev Ranjan I am glad you find it helpful...
Rajeev RanjanPosted Mar 19, 2015, 2:59 AM
thnks for making my concept clear. I really like the way of writing.