📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

πŸ“š .NET Interview Questions

377 questions for senior .NET engineer interviews, each with a 30-second answer, the full answer, a deep dive, the follow-ups interviewers ask next, and real-world production problems.

Collections

ArrayList, List, Dictionary, HashSet, Queue, Stack, SortedDictionary, SortedList, LinkedList, immutable and concurrent collections: using the .NET collection APIs correctly.

  1. What is the difference between ArrayList and List<T> in C#? Why is ArrayList still in .NET, and what goes wrong when you use it in new code?

    Compares the non-generic ArrayList with the generic `List<T>`: type safety, boxing, performance and when you still meet ArrayList.

    Junior Theory Collections Β· πŸ”— 2 follow-ups
  2. How does List<T> work internally? Explain capacity and growth, the cost of Add, Insert and Remove, why modifying a list during foreach throws, and how CollectionsMarshal.AsSpan and EnsureCapacity help in hot paths.

    Internals of `List<T>`: backing array, doubling growth, operation costs, version checks, and modern performance APIs.

    Mid-Level Theory Collections Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  3. How do you use Dictionary<TKey,TValue> correctly in C#? Explain TryGetValue versus ContainsKey plus the indexer, Add versus the indexer setter, TryAdd and GetValueOrDefault, custom comparers, CollectionsMarshal.GetValueRefOrAddDefault, and whether enumeration order is guaranteed.

    Practical `Dictionary<TKey,TValue>` API usage: single-lookup patterns, insert semantics, comparers, ref access and ordering.

    Mid-Level Coding Collections Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  4. How do you use HashSet<T> in C#? Explain Add returning bool, the set operations (UnionWith, IntersectWith, ExceptWith, SetEquals), custom comparers, and why HashSet.Contains beats List.Contains. When would you use SortedSet<T> or FrozenSet<T> instead?

    The `HashSet<T>` API in practice: uniqueness, set algebra, comparers, and the sorted and frozen alternatives.

    Junior Theory Collections Β· πŸ”— 2 follow-ups
  5. How do Queue<T> and Stack<T> work in C#? Explain their internal storage, Enqueue/Dequeue and Push/Pop, the Try methods, the enumeration order, and when you would use PriorityQueue<TElement,TPriority> or a concurrent queue instead.

    The .NET `Queue<T>` and `Stack<T>` APIs, their circular-buffer and array internals, and the priority and concurrent alternatives.

    Junior Theory Collections Β· πŸ”— 3 follow-ups
  6. What is the difference between SortedDictionary<TKey,TValue> and SortedList<TKey,TValue> in C#? How is each implemented, what are the costs of insert, lookup and enumeration, and how do you choose between them (and versus Dictionary)?

    Compares the two sorted key-value collections in .NET: red-black tree versus sorted arrays, costs, memory and use cases.

    Mid-Level Theory Collections Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  7. When would you use LinkedList<T> in C#? Explain how it is implemented, the LinkedListNode<T> API (AddBefore, AddAfter, Remove(node)), its real costs compared with List<T>, and the classic LRU cache that combines it with a Dictionary.

    The .NET doubly linked list: node API, O(1) operations given a node, memory and cache costs, and the LRU cache pattern.

    Mid-Level Coding Collections Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  8. What are immutable collections in .NET? Compare ImmutableArray<T>, ImmutableList<T> and ImmutableDictionary<TKey,TValue>, explain builders and structural sharing, and contrast them with ReadOnlyCollection<T>, IReadOnlyList<T> and FrozenDictionary.

    System.Collections.Immutable types, their internal structures and costs, builders, and how they differ from read-only views and frozen collections.

    Mid-Level Theory Collections Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  9. How do the concurrent collections in .NET work? Explain ConcurrentDictionary (including the GetOrAdd and AddOrUpdate caveats), ConcurrentQueue, ConcurrentStack, ConcurrentBag and BlockingCollection, why compound operations are still not atomic, and when you would use Channel<T> instead.

    System.Collections.Concurrent in depth: locking strategies, atomicity limits, delegate re-execution, expensive members and producer/consumer options.

    Senior Theory Collections Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  10. You are designing a new service and a colleague uses List<T> everywhere. How do you choose the right .NET collection for each job, and what collection types should your public APIs accept and return? Walk through the decision with real examples.

    A senior decision framework for choosing among all .NET collections, plus API surface rules for parameters and return types.

    Senior RealWorldScenario Collections Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world

🌐 Sangam's Webring

βͺ Previous 🏠 Main Next ⏩
πŸ’¬ Chat with me