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.
Warm-up questions
Short questions with short answers, each answered in full.
-
Fresher
What is the difference between .NET and .NET Framework?
Answered in the lesson What C# and .NET are, and which version to use
-
Fresher
How do you check which .NET SDKs and runtimes are installed, and which SDK a folder uses?
-
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
-
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
-
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
-
Fresher
Why does Console.ReadLine() return a nullable string, string?
Answered in the lesson Console input, output, arguments and exit codes
-
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.
-
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
-
- Why not move straight to .NET 11?
- What changes for these services during the maintenance phase?
- How do you stop a build server from picking another SDK during the move?
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.
Passes can’t be bought right now, so the model answers can’t be opened at the moment. If you have a pass, enter your licence key.
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
-
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
-
- What does a program give up with Native AOT?
- How can a program tell whether its code is compiled at run time?
- Why are file-based apps set up for Native AOT by default?
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
-
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
-
- Why did the laptop still work?
- Would latestFeature be a better choice than latestPatch?
- How do you make CI install the right SDK in the first place?
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
-
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
-
- Which runtime does a web API need, and which a console tool?
- When does a server need no .NET install at all?
- How do runtime patches reach the servers?
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
-
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
-
- Where should the error message go, standard output or standard error?
- What exit code does an unhandled exception give?
- How would you use different exit codes for different failures?
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
-
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
-
- What does the first run cost on a fresh build server?
- How would two scripts share code?
- Which signs tell you that a script should become a project?
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
-
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
-
- Why did the laptops never show the problem?
- How would you make the packages available to an offline server?
- What do the tools lose when PublishAot is turned off?
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
-
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
-
- How do you update a package for all twenty scripts at once?
- What do NU1008 and NU1010 tell you once central management is on?
- Where should the nuget.config of these scripts live?
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
-
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
-
- How would you capture more information the next time it happens?
- The recursion is correct, but the data is very deep. What do you change?
- Why does the repeat count differ between machines and builds?
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
-
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
-
- Is Debug.Assert still useful anywhere?
- Should the import stop at the first bad row or collect them all?
- Which test would have caught this before production?
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
-
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
-
- Why was there no exception?
- Would setting the server's culture to en-US be a good fix?
- How do you find and repair the rows already imported?
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
-
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
-
- Should warnings that do not stop the run also go to standard error?
- What should the tool print when it succeeds?
- How would you test that the contract holds?
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
-
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
-
- How would CI notice that fewer tests ran than before?
- Could the tests be skipped even with the project in the solution?
- How do you catch a project missing from the solution automatically?
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
-
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
-
- What will the netstandard2.1 build reject?
- How do you keep code that only the net10.0 build can use?
- Why not target netstandard2.1 alone?
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