Tuesday, August 26, 2014

Difference between IEnumerable and IEnumerator

Difference between IEnumerable and IEnumerator

Hi Geeks,

 

Dotnetpiper

 

Here are few points which I learnt about IEnumerable and IEnumerator.

  1. IEnumerable uses IEnumerator internally.
  2. IEnumerable doesnt know which item/object is executing.
  3. Whenever we pass IEnumerator to another function ,it knows the current position of item/object.
  4. Whenever we pass IEnumerable collection to another function ,it doesn't know the current position of item/object(doesn't know where I am)
  5. IEnumerable have one method GetEnumerator()

IEnumerator have one Property current and two methods Reset and MoveNext.

In simple words: If you want to loop through with the collection one by one and you are not interested in the current cursor position then should opt 

Enumerable.Because code is simple and short.

And if you are keen to know the current position of object then should go for IEnumerate.

 

To know more about MVC please go through with given below link.


MVC Articles


Enjoy Coding and Reading Smile

1 comment :

  1. Tết là thời điểm mua sắm của nhiều người. Tuy nhiên, các mặt hàng ở Việt Nam khác đại trà. Bạn muốn đổi cách mua sắm những sản phẩm tại các nước khác ở trên thế giới. Hãy đến fado để có thể tha ga mua sắm những đồ mình yêu thích tại các trang Amazon của Mỹ, Nhật Bản, Taobao của Trung Quốc, …

    ReplyDelete