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

Phase 2 — C# Fundamentals

The C# language core for .NET 10 and C# 14: language basics, the type system, strings, arrays, collections and exception handling, with the internals and trade-offs senior interviews probe.

  1. What is the difference between a local variable, a const, a readonly field and a static readonly field in C#, and how do literals such as numeric suffixes, digit separators and raw string literals work?

    Variables, constants and literals in C# 14: definite assignment, const versus readonly, the const versioning trap, and every literal form you meet in real code.

    Junior Theory Language Basics Β· πŸ”— 2 follow-ups
  2. What are the built-in numeric data types in C#? When do you use int, long, double or decimal, and how do overflow, checked arithmetic and floating-point precision affect real code?

    Choosing numeric types in C#: integral versus binary floating point versus decimal, silent overflow and checked contexts, NaN and Infinity, rounding, and money calculations.

    Junior Coding Language Basics Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  3. Explain the C# operators you use daily, including the null operators (?., ??, ??=), short-circuit evaluation, integer division and operator precedence. Where do they cause bugs?

    Arithmetic, comparison, logical, null-handling, pattern and index/range operators in C# 14, with precedence rules and the bugs each one commonly causes.

    Junior Theory Language Basics Β· πŸ”— 3 follow-ups
  4. What is the difference between an expression and a statement in C#? Explain switch expressions, pattern matching and expression-bodied members, and when you would use each.

    Expressions versus statements in C# 14, and the expression-oriented features built on that split: switch expressions, the pattern kinds, throw expressions and expression-bodied members.

    Mid-Level Theory Language Basics Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  5. Walk through C# control flow: if, switch, for, foreach, while, break, continue and return. What does foreach compile to, and which loop bugs should you watch for?

    C# selection, iteration and jump statements, how foreach is lowered for arrays, List<T> and IEnumerable<T>, and the classic loop bugs: closure capture, modifying during enumeration, off-by-one and multiple enumeration.

    Junior Debugging Language Basics Β· πŸ”— 2 follow-ups
  6. How are arguments passed to methods in C#? Explain pass-by-value for value and reference types, ref, out, in, ref readonly, params, and optional and named parameters.

    C# parameter passing in depth: copies of values versus copies of references, the ref/out/in/ref readonly modifiers, params collections (C# 13), optional and named arguments, and their performance and versioning trade-offs.

    Mid-Level Theory Language Basics Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  7. Code review: a service method returns null when an order is not found, reports errors through two out parameters, returns its internal List<Order> directly, and is called from async code. How would you redesign its return types, and what return options does C# give you?

    Choosing method return types in C#: void, values, tuples, out parameters, result objects, ref returns, IEnumerable and IAsyncEnumerable, Task and ValueTask, reviewed through a realistic service method.

    Senior CodeReview Language Basics Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  8. What are local functions in C#? How do they differ from lambdas in capture, allocation and recursion, and when do you use a static local function?

    Local functions versus lambdas in C#: syntax, struct versus class closures, delegate allocation, recursion, generics, static local functions, and the eager-validation pattern for iterators and async methods.

    Mid-Level Theory Language Basics Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  9. How do methods work in C#? Explain instance versus static methods, method signatures and overloading (and how overload resolution picks a method), expression-bodied methods, and extension methods including the C# 14 extension members syntax.

    C# methods end to end: instance and static, signatures, overloading rules, expression-bodied form, and classic and C# 14 extension members.

    Mid-Level Theory Language Basics Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  10. What is the difference between value types and reference types in C#? Explain copy semantics, equality, where they are stored, and why "value types live on the stack" is only partly true.

    Value types versus reference types in .NET 10: what each kind is, copy and assignment semantics, default equality, real storage locations, object overhead, and how to choose.

    Junior Theory Types Β· πŸ”— 3 follow-ups
  11. What are nullable value types (Nullable<T>, int?) in C#? How do HasValue, Value, GetValueOrDefault, lifted operators and boxing of a null nullable work?

    Nullable value types in C#: the Nullable<T> struct, safe access patterns, lifted arithmetic and comparison operators, three-valued bool logic, boxing behaviour and database mapping.

    Junior Theory Types Β· πŸ”— 2 follow-ups
  12. What are nullable reference types in C#? Explain the annotations (? and !), how the compiler's null-state flow analysis works, attributes such as [NotNullWhen] and [MemberNotNull], and their limits at run time.

    Nullable reference types (NRT) in C# 14: nullable contexts, annotations and the null-forgiving operator, flow analysis, nullable attributes, generics, and the gaps where nulls still get through at run time.

    Mid-Level Theory Types Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  13. What are boxing and unboxing in C#? Where does hidden boxing happen, what does it cost, and how do you find and remove it?

    Boxing and unboxing in .NET 10: what the runtime does, the exact-type rule for unboxing, the common hidden boxing sites, the cost in allocations and GC, and the tools and fixes to remove it.

    Mid-Level Debugging Types Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  14. How does type inference work in C#? When should you use var, target-typed new and inferred lambda types, and when does explicit typing read better?

    Type inference in C# 14: var and its rules, anonymous types, target-typed new and collection expressions, generic method inference, natural lambda types, and the readability and LINQ traps that guide when to be explicit.

    Junior Theory Types Β· πŸ”— 2 follow-ups
  15. What does default mean in C#? Explain default(T), the default literal, default values of structs, enums and reference types, and how default is used in generics and optional parameters.

    The default keyword and default values in C# 14: all-zero memory, default(T) and the default literal, struct and enum pitfalls, generic code that returns default, and the other meanings of the word default in C#.

    Junior Theory Types Β· πŸ”— 2 follow-ups
  16. Every C# type derives from System.Object. What members does it give you? Then review a Customer class that overrides Equals to compare Email but does not override GetHashCode: what breaks, and how do you implement equality correctly (or use a record)?

    System.Object's members and contracts, reviewed through a broken Equals override: the Equals/GetHashCode contract, IEquatable<T>, operators, inheritance pitfalls, records, ToString and MemberwiseClone.

    Mid-Level CodeReview Types Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  17. What is dynamic in C#? How does the DLR bind calls at run time, how does it differ from object and var, and when is it a reasonable choice?

    The dynamic type in C#: run-time binding through the DLR and call-site caches, comparison with object and var, the costs (errors at run time, performance, trimming and AOT), and the narrow cases where it is still justified.

    Mid-Level Theory Types Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  18. What does it mean that string is immutable in C#? What really happens in memory when you "modify" a string, and why did .NET make strings immutable?

    The System.String type and its immutability: memory layout, what concatenation, Replace and ToUpper actually do, why immutability gives thread safety, hashing and security benefits, and its allocation cost.

    Junior Theory Strings Β· πŸ”— 2 follow-ups
  19. What is string interning in .NET? Which strings are interned automatically, how do string.Intern and string.IsInterned work, and when is interning useful or harmful?

    String interning in .NET 10: the intern pool, automatic interning of literals and constant expressions, explicit string.Intern, reference equality surprises, memory lifetime, and safer alternatives such as custom string pools.

    Mid-Level Theory Strings Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  20. When should you use StringBuilder instead of string concatenation in C#? How does StringBuilder work internally, and what are the alternatives such as string.Join, string.Create and interpolation?

    StringBuilder in .NET 10: when it beats concatenation and when it does not, its chunked internal buffer, capacity, interpolated Append, pooling, thread safety, and the alternatives for each text-building scenario.

    Junior Coding Strings Β· πŸ”— 2 follow-ups

🌐 Sangam's Webring

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