Collections
Data structures for holding similar data, e.g., arrays, maps, etc.
Dated Aug 29, 2025; last modified on Fri, 29 Aug 2025
Data structures for holding similar data, e.g., arrays, maps, etc.
Random Link ¯\_(ツ)_/¯ | ||
Sep 6, 2025 | » | Generic and Non-Generic Collection Interfaces in C#
4 min; updated Sep 6, 2025
There are two main types of collections: non-generic (ICollection) and generic (ICollection<T>). Non-generic collections only exist because .NET did not originally have generic data types. They shouldn’t be used because: They are untyped at compile time. The frequent casting from object and the actual type is error-prone; it’s easy to put the wrong type in the wrong collection. Value types need to be boxed as object, e.g., List<int> stores its data in an int[], which is more performant than using object[] as that requires boxing.... |
Sep 6, 2025 | » | Collection Types in C#
3 min; updated Sep 6, 2025
Choosing a Collection Type In summary, the use cases are: Dictionary<TKey, TValue> for quick look-up by key. List<T> for accessing items by index. Queue<T> for first-in-first-out (FIFO) access where the element is discarded after use. Stack<T> for last-in-first-out (LIFO) access where the element is discarded after use. LinkedList<T> for sequential access from either the head or the tail. ObservableCollection<T> to receive notifications when items are removed/added. SortedList<TKey, TValue> for a collection sorted by keys and accessible by either key or index.... |