By reading similar posts I've learned that a List is a type of IEnumerable. But I'm really wondering what the practical difference between those two actually is.
To someone who always have used a List and never used IEnumerable:
- What is the practical difference between the two?
- In what scenarios is one of them better than the other?
Here is a practical example: We want to store four strings, order them alphabetically, pass them to another function and then show the user the result. What would we use and why?
Hopefully someone can sort this out for me or point me in the right direction. Thanks in advance!
Listisn't a type ofIEnumerableit fulfills the contract thatIEnumerablesets out (i.e. it can be used as anIEnumerable). If you want to store strings you'd use a list. You couldn't use an enumerable as that isn't a class. You could access the list as an enumerable if you wanted. - George Duckett