What is the difference between the non-generic IEnumerable and the generic IEnumerable<T>?

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<int> 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<int> 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?


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


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.