or the other way around?
I use generic lists all the time. But I hear occasionally about IEnumerables, too, and I honestly have no clue (today) what they are for and why I should use them. So, at the risk of having something on the net forever more proclaiming my ignorance, I humbly post this question.
Well,
List<T>implementsIEnumerable<T>… basicallyIEnumerable<T>is just a sequence of items. You can read through it, and that’s all.List<T>is a mutable collection – you can add to it, remove from it, sort it etc. It’s more flexible in itself, butIEnumerable<T>allows you to use the same code to work with any implementation (arrays, linked lists, lists, iterators returned from methods usingyieldstatements etc).