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

Strings

string and its immutability, StringBuilder, interpolation and formatting, culture-sensitive and ordinal comparison, interning, encoding and ReadOnlySpan of char.

  1. 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
  2. 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
  3. 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
  4. How does string interpolation work in C#? Explain interpolated string handlers, FormattableString, raw interpolated strings, which culture is used, and where interpolation is dangerous (SQL and logging).

    String interpolation in C# 14: what $"..." compiles to, interpolated string handlers and their performance, alignment and format specifiers, culture rules, raw interpolated literals, and the SQL-injection and structured-logging traps.

    Mid-Level Theory Strings Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  5. How does string formatting work in .NET? Explain composite formatting, standard and custom format strings for numbers and dates, IFormatProvider and CultureInfo, and when to use the invariant culture.

    String formatting in .NET 10: composite format items, standard and custom numeric and date format strings, IFormatProvider and CultureInfo (including en-AU), parsing with cultures, invariant globalisation mode, and span-based TryFormat.

    Junior Theory Strings Β· πŸ”— 2 follow-ups
  6. What is the difference between ordinal and culture-sensitive string comparison in .NET? When should you use StringComparison.Ordinal, OrdinalIgnoreCase, CurrentCulture and InvariantCulture, and which string methods default to which?

    Ordinal versus linguistic string comparison in .NET 10: how each works, which methods default to culture-sensitive comparison, case-insensitive comparison done right, the Turkish I problem, comparers for collections, and security implications.

    Mid-Level Theory Strings Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  7. After moving a .NET service from Windows (.NET Framework) to Linux containers on .NET 10, string sorting, IndexOf results and some culture formatting changed, and one image failed to start with a culture error. Why, and how do you diagnose and fix culture-sensitive behaviour?

    A real-world culture-sensitive comparison scenario: NLS versus ICU, invariant globalisation mode in slim container images, IndexOf and sort-order changes, time zone ids, and how to make string behaviour deterministic across platforms.

    Senior RealWorldScenario Strings Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  8. How do you work with text encodings in C#? Explain the Encoding class, UTF-8 with and without a BOM, legacy code pages, u8 literals, Rune, grapheme clusters and Unicode normalisation.

    Practical encoding work in .NET 10: Encoding APIs and defaults, BOMs, invalid-byte handling, Windows-1252 via CodePagesEncodingProvider, UTF-8 literals and the Utf8 class, Rune and StringInfo for user-visible characters, and normalisation for comparisons.

    Mid-Level Theory Strings Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  9. What is ReadOnlySpan<char>, and how does it let you parse and slice strings without allocating? Show a parser that uses it, and explain its limitations and when to use ReadOnlyMemory<char> instead.

    ReadOnlySpan<char> for zero-allocation text processing in .NET 10: slicing, span-based parsing and searching, splitting without substrings, stackalloc and ArrayPool buffers, alternate dictionary lookups, ref struct restrictions and ReadOnlyMemory.

    Senior Coding Strings Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  10. Code review: an export method builds a cache key with customer.Name.ToLower() + "_" + date.ToString(), checks status.ToUpper() == "ACTIVE", validates emails with IndexOf("@") > 0, appends CSV rows with result += line, truncates names with Substring(0, 50), calls name.Trim() without assigning it, and logs with $"Exported {count} rows". What is wrong and how would you rewrite it?

    A string-handling code review that combines the Phase 2 string topics: immutability, comparison, culture, formatting, concatenation, truncation, null handling and logging, with a rewritten version.

    Senior CodeReview Strings Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world

🌐 Sangam's Webring

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