QuickDevGuide

Home › C#

Collections & Generics — C#

Type Characteristics Typical use T[] fixed size, fastest known-size buffers List<T> dynamic array most sequences Dictionary<TKey, TValue> O(1) key lookup indexes, caches HashSet<T> unique items, O(1) contains membership, de-dupe Queue<T> / Stack<T> FIFO / LIFO work queues, undo PriorityQueue<T, TPriority> min-heap scheduling, Dijkstra SortedDictionary / SortedSet kept in order ordered lookups ImmutableList, FrozenDictionary (.NET 8) read-only, thread-safe configuration, lookup tables ConcurrentDictionary thread-safe shared caches Generics Define reusable, type-safe code with class Repository<T> where T : IEntity. Constraints include where T : class, struct, new(), a base class or interface. Interfaces to accept Accept the most general type you need (IEnumerable<T>, IReadOnlyList<T>) and…

Key Takeaways