What is the difference between the non-generic IEnumerable and the generic IEnumerable?

An IEnumerable is basically a collection of objects. It has the method GetEnumerator() which allows you to iterate through all of the objects in the enumerable An IEnumerable test = method() means that method() is getting a collection if integers from somewhere. It could be a List, an array or some other data type, but it is definitely a group of them and they are all integers, and you have the ability to iterate through them This post may be helpful as well: What's the difference between IEnumerable and Array, IList and List?

An IEnumerable is basically a collection of objects. It has the method GetEnumerator() which allows you to iterate through all of the objects in the enumerable. An IEnumerable is basically a collection of integers.It has the method GetEnumerator() which allows you to iterate through all of the integers in the enumerable.

IEnumerable test = method(); means that method() is getting a collection if integers from somewhere. It could be a List, an array or some other data type, but it is definitely a group of them and they are all integers, and you have the ability to iterate through them. This post may be helpful as well: What's the difference between IEnumerable and Array, IList and List?

Ok, I think I understand now, I didn't realise it could be a collection and I just didn't understand how it worked. Is there a good resource you can show that shows the benefits/pitfalls comparing IEnumerable/list/arrays as I really want to learn more. +1 (when I can!) – idiot Apr 3 at 10:53 Lists and arrays both implement IEnumerable.

All the generic collections in System.Collections. Generic implement IEnumerable. You may be interested in this post: stackoverflow.

Com/questions/764748/… – smartcaveman Apr 3 at 11:00 Thanks... and marking as answer... You may want to edit/put that link in your main answer as well because that really has made me completely understand now. – idiot Apr 3 at 11:11.

I just think of IEnumerable the same way as I'd think of a List, which comes a little bit more naturally I suppose. With the caveat that an IEnumerable doesn't do quite as much as a List, and that essentially it's just a thing of ints that can be enumerated.

1 I don't really like this analogy. A list assumes that the all the items are in one place. Where as an IEnumerable just says that you can get all of the items in some sequence.It's like the difference between a phone book and the internet.

I can get all the numbers for plumbers in Chicago from either place, but in the Phone Book, they are already in a list - whereas in an IEnumerable or on the internet, they can be whatever, I just need to know how to find them - I didn't downvote you though, I just think your answer could use a little more clarity. – smartcaveman Apr 3 at 3:28 user689466 is looking for a way to understand IEnumerable. Clearly there are differences - it's just a starting point with an easily understandable concept and once he groks that he can move on to understanding the subtleties between the two – qntmfred Apr 5 at 23:17.

The word you're looking for is "generics", and the example you give is IEnumerable being used as a generic for items of type int. What that means is that the IEnumerable collection you are using is strongly-typed to only hold int objects as opposed to any other type. Google "C# generics IEnumerable" and you will find all of the information you want on this.

IEnumerable means it can be used in a foreach loop. Test can be used in the form of foreach(int item : test) { console. Writeline(item); }.

An IEnumerable has a GetEnumerator method which will return an IEnumerator, whose Current method will return an Object. An IEnumerable has a GetEnumerator method which will return an IEnumerator, whose current method will return a T. If you know in advance the expected type of the object to be returned by the enumerator, it's generally better to use the generic form.

Another distinction is that IEnumerator inherits IDisposable, which allows code which is done with an enumerator to call Dispose on it without having to worry about whether it's supported. By comparison, when using a non-generic IEnumerator, it's necessary to test whether it's IDisposable and call Dispose on it if so. Note that use of the non-generic form of IEnumerable/IEnumerator does not relieve one of the requirement to call Dispose.As an example, casting the vb-style Collection to IEnumerable and then calling GetEnumerator 100,000 times without calling Dispose will be extremely slow (many seconds, even on an i7) unless a garbage-collection happens to occur.

Disposing the IEnumerator after each call will speed things up more than a hundredfold.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions