Sorry for such a vague question, but I have been searching around for the best part of a day, I have read article after article (and many questions here) but just cannot find an easy to understand answer.
I (think I) know what IEnumerable is for, but I just can't understand what it means when it is defined with a generic type argument, for example:
IEnumerable<int> test = method();
This is just driving me mad! Please put me out of misery and explain what it means?
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With