While I do a program, sometimes I’ve got this doubt. I have been using List<T> but I haven’t used the others.
I’d like to know when each one is better to use, and under what circumstances.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’m sure you can read the documentation by yourself. I’ll give a short summary here:
IEnumerableis an interface that exposes an enumerator over a collection. Implement this interface if want to be able to support iteration, for example inside aforeachloop.Collectionis an implementation ofIEnumerable(therefore you can iterate over it) that is generally further extended by user-defined classes that want to have collection-like behavior (i.e. useAdd,Remove,Contains, etc.). It can also be used “as-is”.Listis also an implementation ofIEnumerable(therefore you can iterate over it) that is generally used “as-is” as a container for objects of a certain type. Uses a dynamically adjusting array in the background and is the generic equivalent ofArrayList.Note that while
IEnumerablecan be both generic and non-generic,CollectionandListcan only be used as generic classes.