Click here to Skip to main content
15,905,971 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Frends ,
had very basic doubt , requesting you help in understand.

we can add or delete in ienumerable ,but in ienumerable internally returns ienumerater only why ienumerable allows collection modify.
and why ienumerator not allows modify.

or why ienumerater is readonly.

Thanks
Raja
Posted
Updated 17-Dec-13 4:00am
v2

1 solution

Hi,

First of all IEnumerable and IEnumerator are both interfaces. You can think of IEnumerable as a container which contains one method which returns you IEnumeator type of object.

Second, when you are creating your own custom collection class on which you want to iterate then you must derive from IEnumerable to support Iteration over that collection class.

And further you can write the GetEnumerator method in your collection class which returns you IEnumerator object which helps you or provide basic info.

like 1) what is current object which iterating over the collection, 2) MoveNext() method -- are there more elements in collection for iteration??, 3) And Reset() -- resets the iterator pointer.

Hope this helps!
 
Share this answer
 
Comments
rajacsharp5 17-Dec-13 10:20am    
thanks for reply pankaj, this definition iam very much aware, please understand ,im looking for the reason behind.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900