Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

C# & .NET (C# 14, .NET 10 LTS) Module 1

Start here: C#, .NET and your first programs interview questions

Interview questions on “Start here: C#, .NET and your first programs”: warm-ups, then what each harder question tests and how a good answer starts.

21 questions: 7 warm-ups and 14 with model answers · Levels: Fresher to senior

Warm-up questions

Short questions with short answers, each answered in full.

  1. Fresher

    What is the difference between .NET and .NET Framework?

    Answered in the lesson What C# and .NET are, and which version to use

  2. Fresher

    How do you check which .NET SDKs and runtimes are installed, and which SDK a folder uses?

    Answered in the lesson Install and pin the .NET SDK

  3. Fresher

    What are top-level statements in C#, and what does the compiler do with them?

    Answered in the lesson Your first C# program as a file-based app

  4. Fresher

    What do the #: lines at the top of a file-based C# app do?

    Answered in the lesson Packages and settings in file-based apps

  5. Fresher

    What is the difference between a compiler error and a warning in C#, and what does TreatWarningsAsErrors change?

    Answered in the lesson Compiler errors, stack traces and debugging

  6. Fresher

    Why does Console.ReadLine() return a nullable string, string?

    Answered in the lesson Console input, output, arguments and exit codes

  7. Fresher

    What is the difference between a project and a solution in .NET?

    Answered in the lesson Projects, solutions and the dotnet CLI

Questions with model answers

What each question tests, the first step of a good answer and the follow-ups to expect.

  1. Mid to senior

    Your team runs three services on .NET 8 and one on .NET 9, and the support of both ends on the same day. Plan the upgrade: which version do you move them to, what do you check first, and how do you keep the change safe?

    What it tests
    How LTS and STS support and the maintenance phase work, choosing a supported target, and ordering a framework upgrade so that builds and deployments stay reproducible.
    First step
    Start from the support policy: .NET 8 (LTS) and .NET 9 (STS) end together and, in their last six months, get security fixes only. .NET 10 is the supported LTS release, with three years from its release in 2025, so it is the target for all four. Then take an inventory: each service's target framework, its global.json pin and the packages that must support net10.0.
    Follow-ups

    From the lesson What C# and .NET are, and which version to use

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.

    Opening the model answers with your pass…

    Model answers open with any MySmartCoPilot pass.

    • Pro pass · 1 week₹79$2.99
    • 30 days₹179$5.99
    • 1 year₹1,699$45

    One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.

    It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 4 minutes
  2. Fresher to mid

    A colleague says C# programs start slowly because the .NET runtime interprets them. Explain what really happens between the source file and the processor, and when you would publish with Native AOT instead.

    What it tests
    The pipeline from C# to IL in an assembly and from IL to machine code, what start-up time pays for, and the trade-offs of Native AOT.
    First step
    Correct the word first: nothing interprets the code. Roslyn compiles C# into IL in an assembly, and the runtime's JIT compiles each method into machine code just before its first call, so start-up includes that compiling. Native AOT moves all of it to publish time.
    Follow-ups

    From the lesson What C# and .NET are, and which version to use

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  3. Fresher to mid

    A build passes on your laptop but fails on the build server with "A compatible .NET SDK was not found". The repository's global.json asks for 10.0.401 with rollForward disable. Explain what happened, fix it, and keep it from happening again.

    What it tests
    Reading the SDK-not-found message, how global.json and rollForward choose an SDK, and pinning a repository so that patch updates on build servers do not break it.
    First step
    Read the message: it names the requested version, the global.json that asked for it and the SDKs the server has. The server most likely has a newer patch, such as 10.0.402, because its installer replaced 10.0.401 within the band, and disable accepts only the exact version.
    Follow-ups

    From the lesson Install and pin the .NET SDK

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  4. Fresher to mid

    Your team wants to install the full .NET SDK on every production server, to be safe. What would you install instead, and why?

    What it tests
    The difference between the SDK and the runtimes, which runtime an app needs, keeping servers patched, and keeping production machines small.
    First step
    Separate building from running. The SDK holds the compiler, MSBuild and NuGet, which production never uses. A framework-dependent app needs only the runtime it targets, such as the ASP.NET Core runtime 10.0 for a web app, kept on its latest patch.
    Follow-ups

    From the lesson Install and pin the .NET SDK

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  5. Fresher to mid

    A C# file-based tool runs in your CI pipeline. It prints "error: 3 files missing", yet the pipeline step passes and a later step fails in a confusing way. Explain why, and how you would make the tool report its failure properly.

    What it tests
    Exit codes and how shells and CI read them, how top-level statements set them, and failing early with clear output.
    First step
    CI decides pass or fail by the exit code, never by the text, and top-level code that ends without a return exits with 0. So the tool must end with a non-zero code when it fails, such as return missing.Count > 0 ? 1 : 0;, and write its error to standard error.
    Follow-ups

    From the lesson Your first C# program as a file-based app

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  6. Mid to senior

    Your team keeps its small automation scripts in Bash and Python. Someone proposes C# file-based apps instead. What would you check before agreeing, and when should such a script become a project?

    What it tests
    What file-based apps give and cost, such as one file, packages, a build cache and a shebang against a first-run build and a required SDK, and when to convert one into a project.
    First step
    List what the scripts need: where they run, whether every machine has the .NET 10 SDK, how often they start, and which libraries they use. File-based apps need the SDK, build on their first run and cache the build; they pay off when the team already writes C# and wants types and NuGet packages.
    Follow-ups

    From the lesson Your first C# program as a file-based app

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  7. Mid to senior

    File-based tools that work on developers' laptops fail on an offline build server with NU1301 before compiling anything, even the ones that use no packages. Explain the cause, and give two fixes with their trade-offs.

    What it tests
    What restore needs for a file-based app, the PublishAot default and the packages it adds, and the ways to build without internet access.
    First step
    Read NU1301 as a restore failure: the build never reached the compiler. A file-based app has PublishAot=true by default, so restore wants the Native AOT packages. The laptops downloaded them once into their package folders; the offline server cannot.
    Follow-ups

    From the lesson Packages and settings in file-based apps

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  8. Mid to senior

    A teammate writes #:package Spectre.Console@* in each of twenty scripts. What could go wrong, and how would you manage the package versions of all twenty?

    What it tests
    Floating versions against reproducible builds, central package management for file-based apps, and keeping a set of scripts maintainable.
    First step
    Point out that @* floats: each restore may pick a newer version, so the same script can build differently on two machines or break overnight. Then pin: one Directory.Packages.props above the scripts, with central package management on, holding each version once.
    Follow-ups

    From the lesson Packages and settings in file-based apps

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  9. Fresher to mid

    A service crashes in production. Its log ends without any error line, and its console shows "Stack overflow." with one frame repeated thousands of times. Why did the logging in your catch blocks never run, and how do you find and fix the cause?

    What it tests
    That a stack overflow ends a .NET process without running catch blocks, reading the repeated-frames summary, and fixing recursion that has no bound.
    First step
    Explain that .NET cannot catch a stack overflow: the runtime prints "Stack overflow.", the repeated frame and the frame that started it, then ends the process, so no catch block, finally block or logger runs. The repeated frame names the method that recursed; start there and find the input that made it go on without end.
    Follow-ups

    From the lesson Compiler errors, stack traces and debugging

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  10. Fresher to mid

    A teammate checked every record of an import with Debug.Assert. Runs from the IDE stopped on bad records, but the production service, a Release build, imported 1,200 invalid rows without a word. Explain what happened and how you would change the checks.

    What it tests
    How Debug methods are compiled only with the DEBUG symbol, the difference between assertions and validation, and choosing exceptions or collected errors for input that can be wrong.
    First step
    Point out that Debug.Assert carries Conditional("DEBUG"): a Release build does not define DEBUG, so the compiler left out every assertion and nothing checked the rows. Input checks must stay in every build, so replace them with code that throws, or that collects the invalid rows and reports them.
    Follow-ups

    From the lesson Compiler errors, stack traces and debugging

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  11. Fresher to mid

    A price import parses values such as 2.50 from a supplier's CSV file. It worked for months; then a new server set up for Germany imported every price 100 times too high, without a single error. Explain what happened, how you fix it, and how you find the rows already imported wrongly.

    What it tests
    How the current culture changes Parse and ToString, choosing the invariant culture for text that programs exchange, and repairing data that a silent parsing bug has damaged.
    First step
    Name the cause: decimal.Parse without a culture uses the current culture, and de-DE reads the dot as a group separator, so "2.50" became 250. Fix the code by passing CultureInfo.InvariantCulture, or the culture the file format defines, to every Parse and ToString of the import.
    Follow-ups

    From the lesson Console input, output, arguments and exit codes

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  12. Fresher to mid

    Your C# command-line tool runs in shell pipelines and CI jobs. Users complain that error messages end up inside the output files and that failed runs still let the next step start. Redesign the tool's contract with its callers.

    What it tests
    Standard output against standard error, exit status conventions, failing fast on usage errors, and testing that contract.
    First step
    State the contract: results only on standard output, every message about a problem on standard error, and a documented exit status, 0 for success, 1 for bad data and 2 for wrong usage. Then check the arguments before any work, so that a mistyped command fails at once with a usage line.
    Follow-ups

    From the lesson Console input, output, arguments and exit codes

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  13. Fresher to mid

    A new test project was merged a month ago, and its tests caught a bug only when someone ran them by hand. CI runs dotnet test on the solution and stayed green the whole time. What went wrong, and how do you make sure it cannot happen again?

    What it tests
    How dotnet test picks the projects of a solution, checking that tests actually ran, and guarding a build against test projects that nothing runs.
    First step
    Check whether the project is in the solution with dotnet sln list. dotnet test on a solution builds and runs only the projects the solution lists, so a project made with dotnet new but never added with dotnet sln add is invisible to CI. Add it, then make CI check how many tests ran.
    Follow-ups

    From the lesson Projects, solutions and the dotnet CLI

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  14. Mid to senior

    Your team's validation library targets net10.0 and is used by two web services. A game team now wants to call it from Unity. What do you change in the project, and what can go wrong?

    What it tests
    Target framework monikers, multi-targeting with TargetFrameworks, the gap between net10.0 and .NET Standard 2.1, and keeping one code base for two targets.
    First step
    Unity's default API level is .NET Standard 2.1, which cannot load a net10.0 library. Multi-target it with <TargetFrameworks>net10.0;netstandard2.1</TargetFrameworks>, so one project builds a .dll for each, then fix what the netstandard2.1 build rejects.
    Follow-ups

    From the lesson Projects, solutions and the dotnet CLI

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes

All C# & .NET (C# 14, .NET 10 LTS) interview questions · The C# & .NET (C# 14, .NET 10 LTS) track

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.