When do you use a List and when do you use a Dictionary?
- The choice of using a List or a Dictionary depends on the requirement, since both serve different purposes.
- A List represents a dynamic linear sequence of elements, and offers index-based access along with utility methods such as Add, Remove, Count, Min, Max and so on based on the type of the objects being added to the List.
- If the emphasis is on manipulating the sequence of elements, then List is a good choice.
- A Dictionary represents a generic set of KeyValue pairs with each row represented by a unique Key mapped to a value.
- Dictionary is used in cases where the emphasis is on quickly looking up for a value since a Dictionary offers constant time lookup.
Posted May 14, 2021