Home > C# > Different between IEnumerable and IEnumerator

Different between IEnumerable and IEnumerator

Normally we used for each to iterate the collection.
IEnumerable doesn’t maintain state of the current Position.

If you want to work on collection, like filter the collection, Sorting, grouping, etc you can better to use IEnumerable.

IEnumerable is suitable for LINQ to Object and LINQ to XML queries. IEnumerable can move forward only over a collection, it can’t move backward and between the items. It is best to query data from in-memory collections like List, Array etc

IEnumerator:-

while statement we used to iterate the collection.
IEnumerator maintain state of the current Position.

Methods 
1) MoveNext()
2) Reset()

Properties
1) Current

Advertisements
Categories: C# Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: