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


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

1) MoveNext()
2) Reset()

1) Current

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 )


Connecting to %s

%d bloggers like this: