📁 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.

  1. What is an array, and how does List<T> build on it in .NET? Explain memory layout, indexing cost, how List<T> grows, and when you would use an array, List<T> or Span<T>.

    Arrays as contiguous memory, O(1) indexing, List<T> as a growable array with capacity doubling, amortised O(1) Add, and when to use arrays, lists, spans and pooled buffers.

    Junior Theory Data Structures Β· πŸ”— 3 follow-ups
  2. What is a linked list? Compare LinkedList<T> with List<T> in .NET, including big-O and real-world performance, and give a case where a linked list is the right choice.

    Singly and doubly linked lists, O(1) node insert/remove vs O(n) search, poor cache locality, LinkedList<T> in .NET, and the LRU cache as a classic use.

    Intermediate Theory Data Structures Β· πŸ”— 2 follow-ups
  3. Explain stacks and queues. How are Stack<T> and Queue<T> implemented in .NET, where do you see them in real systems, and which thread-safe alternatives would you use?

    LIFO and FIFO structures, their array-based implementations in .NET, the call stack, undo, BFS and work queues, plus ConcurrentStack, ConcurrentQueue and Channels.

    Junior Theory Data Structures Β· πŸ”— 3 follow-ups
  4. How does a hash table work? Explain how Dictionary<TKey,TValue> in .NET stores and finds entries, handles collisions and resizes, and what GetHashCode and Equals must guarantee.

    Hash table fundamentals and .NET Dictionary internals: buckets and entries, chaining, load and resizing, the GetHashCode/Equals contract, average vs worst-case cost, and hash flooding protection.

    Mid-Level Theory Data Structures Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  5. A Dictionary-based cache in a .NET service gets slower and slower and sometimes "loses" entries that were definitely added. What could be wrong with the key type, and how would you debug and fix it?

    Debugging hash-based collection failures: constant or poor GetHashCode, mutable keys, inconsistent Equals, culture-sensitive comparisons, and thread-unsafe access to Dictionary.

    Senior Debugging Data Structures Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  6. What is a set? When would you use HashSet<T>, SortedSet<T>, FrozenSet<T> or ImmutableHashSet<T> in .NET, and what set operations do they support?

    Sets as collections of unique items, hash vs tree-based sets, set algebra (union, intersection, difference), frozen and immutable variants, and common performance wins over List.Contains.

    Intermediate Theory Data Structures Β· πŸ”— 3 follow-ups
  7. A map (dictionary) associates keys with values. Compare the map types in .NET: Dictionary, SortedDictionary, SortedList, OrderedDictionary, ConcurrentDictionary, FrozenDictionary, ImmutableDictionary and ILookup. How do you choose?

    The map abstraction and .NET's map implementations: hash vs tree vs sorted array, ordering, concurrency, frozen and immutable variants, multi-maps, and how to choose by access pattern.

    Mid-Level Theory Data Structures Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  8. What are trees, binary trees and binary search trees? Explain traversals, why balance matters, and where trees appear in real .NET systems and databases.

    Tree terminology, binary trees and BSTs, in/pre/post/level-order traversals, balanced trees (red-black, AVL), B-trees in database indexes, and real-world trees in .NET.

    Mid-Level Theory Data Structures Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  9. What is a heap data structure, and how does PriorityQueue<TElement,TPriority> work in .NET? Show how you would find the top K items from a large stream efficiently.

    Binary and d-ary heaps stored in arrays, heap operations and costs, PriorityQueue in .NET (min-heap, no stability, Remove in .NET 9), and classic uses: top-K, scheduling, merging sorted streams and Dijkstra.

    Mid-Level Coding Data Structures Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  10. What is a graph data structure? How do you represent one in C#, and where do graphs show up in real backend systems (dependencies, workflows, permissions)? How would you detect a cycle or find a valid execution order?

    Graph terminology, adjacency list vs matrix vs edge list, directed acyclic graphs, topological sort and cycle detection, and real-world graphs such as DI containers, build systems and job schedulers.

    Senior Theory Data Structures Β· πŸ”— 4 follow-ups Β· πŸ›  1 real-world
  11. What is a trie (prefix tree)? Implement insert, exact search and prefix search in C#, and discuss when a trie is the right choice for something like autocomplete versus alternatives.

    Trie structure and operations, O(L) insert and search, prefix queries, memory trade-offs and compressed (radix) tries, and alternatives such as sorted arrays, database prefix queries and search engines.

    Mid-Level Coding Data Structures Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  12. Code review: an OrderService keeps orders in a static List<Order>, finds them with FirstOrDefault, dedups with Any before Add, gets recent orders with OrderByDescending().ToList().Take(10), checks a blocklist with new List<string>{...}.Contains, drains a List with RemoveAt(0), and counts with ContainsKey plus the indexer. What is wrong, and how would you rewrite it?

    A collection-focused code review: O(n) lookups and dedup, sorting everything for top-N, per-call allocations, List used as a queue, double dictionary lookups, thread safety and unbounded growth.

    Senior CodeReview Data Structures Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  13. What is Big O notation? Explain O(1), O(log n), O(n), O(n log n), O(n²) and O(2ⁿ) with .NET examples, and the difference between best, average, worst-case and amortised cost.

    Big O notation as a growth-rate language: the common complexity classes, real .NET examples of each, and best/average/worst/amortised analysis.

    Junior Theory Algorithms Β· πŸ”— 3 follow-ups
  14. Code review: what is the time complexity of this .NET code, and how would you make it faster? It loops over orders, calls products.FirstOrDefault(p => p.Id == line.ProductId) per line, builds a report with string +=, and checks seen.Contains(order.Id) on a List<int>.

    Analysing the real time complexity of everyday .NET code with hidden loops, and rewriting it to linear time.

    Mid-Level CodeReview Algorithms Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  15. What is space complexity? How do you analyse the memory an algorithm uses in .NET, including auxiliary space, recursion depth, allocations and the GC, and how do you trade time for space?

    Space complexity in practice: auxiliary versus input space, stack depth from recursion, allocation cost in .NET, and time-space trade-offs.

    Intermediate Theory Algorithms Β· πŸ”— 3 follow-ups
  16. How does binary search work? Implement it in C#, explain its preconditions and edge cases, and compare it with linear search and hash lookup. When would you use each in a .NET application?

    Searching algorithms: linear search, binary search (with a correct implementation and edge cases), hash lookup, and choosing between them in .NET.

    Intermediate Coding Algorithms Β· πŸ”— 3 follow-ups
  17. Which sorting algorithm does .NET use for Array.Sort and List<T>.Sort, and is it stable? Compare quicksort, merge sort, heap sort and insertion sort, and explain when OrderBy, a custom comparer or a non-comparison sort is the better choice.

    Sorting algorithms and their trade-offs, .NET's introsort, stability, OrderBy versus Array.Sort, comparers, and when to use counting or radix sort.

    Mid-Level Theory Algorithms Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  18. What is recursion? Explain base cases, the call stack and stack overflow in .NET, then write a recursive and an iterative version of a tree or folder walk in C#. When should you avoid recursion?

    Recursion fundamentals: base and recursive cases, how the call stack works, StackOverflowException in .NET, and converting recursion to iteration with an explicit stack.

    Junior Coding Algorithms Β· πŸ”— 3 follow-ups
  19. What is dynamic programming? Explain overlapping subproblems and optimal substructure, compare memoisation (top-down) with tabulation (bottom-up), and solve a problem such as minimum coins for an amount in C#.

    Dynamic programming basics: recognising overlapping subproblems and optimal substructure, memoisation versus tabulation, and a worked minimum-coins example with space optimisation.

    Mid-Level Coding Algorithms Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  20. What is a greedy algorithm? Give examples where greedy is optimal (interval scheduling, Dijkstra, Huffman) and where it fails (coin change with arbitrary coins, 0/1 knapsack). How do you decide whether greedy is safe in a real system?

    Greedy algorithms: the greedy-choice property, classic optimal cases, counterexamples, and using greedy heuristics in production scheduling and allocation.

    Mid-Level Theory Algorithms Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world

🌐 Sangam's Webring

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