Skip to main content

The .NET Platform and Your First C# Program – C# | Lesson 30

Published / updated

Introduction​

The SMS database is built. Now you learn the language that will talk to it: C# (pronounced "C sharp"). C# runs on .NET, a free platform from Microsoft that works on Windows, Linux, and macOS.

In this lesson, you learn what .NET is, what happens when you press Run, and you create the first project of the SMS solution.

By the end of this lesson, you will be able to:

  • Explain the parts of .NET: SDK, runtime, CLR, and base class library.
  • Describe how C# becomes a running program: compiler, IL, and JIT.
  • Create a solution and a console project with the dotnet command.
  • Read a project file and a Program.cs with top-level statements.
  • Run a quick experiment as a single-file app.

Why this matters​

Every part of the SMS from here on is C# on .NET: the console tools in Modules 6 to 8, the data access in Module 9, and the Web API in Modules 10 to 12.

When something goes wrong, such as "it works on my machine but not on the server", the cause is often in the platform, not in your code. A developer who knows what the SDK, the runtime, and the build output are can fix it in minutes.

The concept​

Example: the parts of .NET​

PartWhat it isAnalogy
C#The language you writeThe recipe
CompilerTurns C# into ILThe person who rewrites the recipe in a standard format
IL (Intermediate Language)The compiled code inside a .dll fileThe standard recipe card
CLR (Common Language Runtime)Runs IL, manages memory, handles errorsThe cook
Base class libraryReady-made code: text, dates, files, networkingThe kitchen's tools
RuntimeThe CLR plus the base class libraryA working kitchen
SDKThe runtime plus the compiler and the dotnet toolsThe kitchen plus the recipe-writing desk

Users who only run an app need the runtime. You, the developer, need the SDK. You installed it in Lesson 4.

Example: from C# to a running program​

  1. Build: the compiler checks your C# and turns it into IL, saved in a .dll file.
  2. Run: the CLR loads the .dll.
  3. JIT (Just-In-Time) compilation: the first time each method runs, the CLR turns its IL into machine code for this exact computer.

Why the middle step? The same .dll runs on Windows, Linux, and macOS, because each one's CLR does its own final translation.

Example: .NET, .NET Framework, and versions​

.NET Framework.NET (this course)
Runs onWindows onlyWindows, Linux, macOS
Latest version4.8.1, maintenance only10, released November 2025
Used forOlder business appsNew projects

Old tutorials and many existing company systems use .NET Framework. The C# language is almost the same, but project files and some libraries differ, so check which one a tutorial uses.

A new .NET version comes out every November. Even numbers, such as .NET 10, are LTS (Long Term Support): Microsoft supports them for three years. That is why companies, and this course, choose .NET 10.

Example: the dotnet commands you will use​

CommandWhat it does
dotnet new sln -n NameCreates an empty solution file
dotnet new console -n Name -o folderCreates a console project
dotnet sln add path.csprojAdds a project to the solution
dotnet buildCompiles everything and reports errors
dotnet run --project folderBuilds, then runs one project
dotnet --list-sdksShows which SDKs are installed

A solution (.slnx file) groups projects that belong together. By Module 12, the SMS solution holds a console app, a core library, a data library, an API, and tests.

Apply it to the SMS​

Step 1: create the solution and the console project​

Open a terminal in your SMSCOURSE folder, the one with database and queries, and run:

Terminal
dotnet new sln -n SchoolApp
dotnet new console -n SchoolApp.Console -o src/SchoolApp.Console
dotnet sln SchoolApp.slnx add src/SchoolApp.Console/SchoolApp.Console.csproj

You now have SchoolApp.slnx in the root, and the project in src/SchoolApp.Console. The .slnx format is the new, simpler solution format that .NET 10 creates by default.

Step 2: read the project file​

src/SchoolApp.Console/SchoolApp.Console.csproj
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
SettingMeaning
OutputType ExeBuild a program you can run, not a library
TargetFramework net10.0Build for .NET 10
ImplicitUsingsCommon namespaces, such as System, are available in every file
NullableThe compiler warns about possible missing values (Lesson 35)

Step 3: write the first program​

Replace the "Hello, World!" line in Program.cs with the SMS welcome banner:

src/SchoolApp.Console/Program.cs
// Lesson 30: the first program in the SMS solution.
// Prints a welcome banner, today's date, and the .NET version running this code.
using System.Runtime.InteropServices;

Console.WriteLine("NexCoding Public School");
Console.WriteLine("School Management System - console tools");
Console.WriteLine("----------------------------------------");
Console.WriteLine($"Today: {DateTime.Now:dddd, d MMMM yyyy}");
Console.WriteLine($"Running on: {RuntimeInformation.FrameworkDescription}");
Console.WriteLine($"Operating system: {RuntimeInformation.OSDescription}");

This file has no class and no Main method. Since C# 9, a program can start with top-level statements: the compiler wraps them into a Main method for you. Each line ends with a semicolon.

Console.WriteLine prints one line. The $"..." text with {...} inside is an interpolated string, which puts values into text; Lesson 33 covers it.

Step 4: run it​

Terminal
dotnet run --project src/SchoolApp.Console
Output
NexCoding Public School
School Management System - console tools
----------------------------------------
Today: Monday, 5 October 2026
Running on: .NET 10.0.11
Operating system: Microsoft Windows 10.0.26200

Your date, .NET patch number, and operating system will differ. What matters is that it says .NET 10.

Example: what the build produced​

dotnet run built the project first. The results are in bin/Debug/net10.0:

FilePurpose
SchoolApp.Console.dllYour code, compiled to IL
SchoolApp.Console.exeA small Windows launcher for the .dll
SchoolApp.Console.pdbDebug information: lets the debugger map IL back to your lines
SchoolApp.Console.runtimeconfig.jsonTells the CLR which .NET version to use
SchoolApp.Console.deps.jsonLists the libraries the app depends on

You can run the IL directly with dotnet bin/Debug/net10.0/SchoolApp.Console.dll. Never edit or commit the bin and obj folders; the build recreates them, and .gitignore keeps them out of git.

Example: quick experiments with a single file​

.NET 10 can run a single .cs file without a project:

Terminal
dotnet run library-assignment/030-library-welcome.cs

This is perfect for trying an idea in a few lines. The SMS itself stays a proper project, because real applications need several files, settings, and libraries.

Example: the same project in an editor​

In Visual Studio 2026, open SchoolApp.slnx. Press Ctrl+F5 to run without the debugger, or F5 to run with it (Lesson 36).

In VS Code with the C# Dev Kit, open the SMSCOURSE folder. The Solution Explorer panel shows the same solution. All three ways, terminal or either editor, run the same dotnet tools underneath.

Common mistakes​

  1. Running dotnet run in the wrong folder. In the root you get "Couldn't find a project to run." Fix: add --project src/SchoolApp.Console, or cd into the project folder.
  2. A missing semicolon. The build fails with error CS1002: ; expected, with the line and column. Fix: read the position in brackets, such as (1,45), and add the ;.
  3. Wrong letter case. console.WriteLine fails with error CS0103: The name 'console' does not exist. Fix: C# is case-sensitive; write Console.
  4. Following a .NET Framework tutorial. Project files and setup steps do not match. Fix: check that a tutorial targets .NET 6 or later.
  5. Editing or committing bin and obj. Fix: change only your source files.

In real projects​

From 16 years of .NET projects

A new developer once told me the API "only works on my machine". The server had the ASP.NET Core runtime for an older .NET version, and the app needed .NET 10.

One look at the runtimeconfig.json file and the server's dotnet --list-runtimes showed the gap. It took two minutes to diagnose.

Knowing what the build produces, and what each file is for, is not theory. It is how you fix deployment problems while everyone else is still guessing.

Best practices​

  • Use the current LTS version of .NET for new projects.
  • Keep one solution per system, with projects inside src and tests folders.
  • Build often; fix the first compiler error first, since later errors often come from it.
  • Never commit bin and obj; keep a proper .gitignore.
  • Use single-file apps for experiments, and projects for real code.

Recap​

  • .NET is the platform; C# is the language; the SDK is what developers install.
  • The compiler turns C# into IL in a .dll; the CLR runs it, and the JIT turns IL into machine code.
  • .NET runs on Windows, Linux, and macOS; .NET Framework is Windows-only and old.
  • dotnet new, dotnet sln add, dotnet build, and dotnet run manage the SMS solution.
  • Program.cs uses top-level statements: no class or Main method needed.

Homework​

Library module task: Create a single-file app, library-assignment/030-library-welcome.cs, that prints a welcome screen for the school library: the title, today's date, the loan period (14 days), and the late fine (2 per day). Run it with dotnet run.

A correct result looks like:

Output
NexCoding Public School - Library
---------------------------------
Today: Monday, 5 October 2026
Loan period: 14 days
Late fine: 2 per day
Show the solution
library-assignment/030-library-welcome.cs
// Library homework, Lesson 30: a welcome screen for the school library.
// A file-based app: run it with dotnet run library-assignment/030-library-welcome.cs
Console.WriteLine("NexCoding Public School - Library");
Console.WriteLine("---------------------------------");
Console.WriteLine($"Today: {DateTime.Now:dddd, d MMMM yyyy}");
Console.WriteLine("Loan period: 14 days");
Console.WriteLine("Late fine: 2 per day");

No project file is needed: dotnet run builds the single file into a temporary project behind the scenes.

Quiz​

  1. What does a developer install to build C# apps?

    1. The runtime
    2. The SDK
    3. Only Visual Studio
    4. .NET Framework
    Show answer

    Answer: B. The SDK The SDK includes the runtime plus the compiler and dotnet tools.

  2. What is inside SchoolApp.Console.dll?

    1. C# source code
    2. IL code
    3. Machine code for Windows only
    4. The database
    Show answer

    Answer: B. IL code The compiler turns C# into IL; the JIT turns IL into machine code at run time.

  3. What does the JIT compiler do?

    1. Checks C# for errors
    2. Turns IL into machine code when methods first run
    3. Installs .NET
    4. Creates projects
    Show answer

    Answer: B. Turns IL into machine code when methods first run Just-In-Time: the final translation happens on the computer that runs the app.

  4. You run dotnet run in the SMSCOURSE root and get 'Couldn't find a project to run'. What is the fix?

    1. Reinstall .NET
    2. Add --project src/SchoolApp.Console
    3. Delete the solution
    4. Use .NET Framework
    Show answer

    Answer: B. Add --project src/SchoolApp.Console The root holds a solution, not a project; tell dotnet which project to run.

  5. Why is .NET 10 a good choice for a new project?

    1. It is the only version
    2. It is an LTS release with three years of support
    3. It runs only on Windows
    4. It needs no SDK
    Show answer

    Answer: B. It is an LTS release with three years of support Even-numbered releases are Long Term Support.

Interview questions​

Questions are grouped by experience level. Click a question to see a model answer. All questions: C# interview questions.

Fresher (0-2 yrs)​

F What is the CLR? concept

The Common Language Runtime is the part of .NET that runs your compiled code. It loads the IL, turns it into machine code with the JIT compiler, manages memory with the garbage collector, and handles exceptions.

See the example · Permalink

F What is IL, and where is it stored? concept

IL (Intermediate Language) is what the C# compiler produces: a platform-neutral set of instructions stored in the .dll file. The CLR turns it into machine code when the program runs.

See the example · Permalink

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

.NET Framework is the original, Windows-only platform; version 4.8.1 is the last, and it only gets maintenance. .NET (Core, then .NET 5 and later) is cross-platform, faster, and where all new development happens.

See the example · Permalink

Mid (3-5 yrs)​

M What does JIT compilation mean, and why does .NET use it? concept

Just-In-Time compilation turns IL into machine code the first time each method runs, on the machine that runs it. The same .dll can therefore run on Windows, Linux, and macOS, and the JIT can optimize for the exact processor.

See the example · Permalink

M What are top-level statements? concept

Code written directly in Program.cs without a class or Main method. The compiler generates the Main method for you. Only one file in a project can have them, and they are ideal for small programs and for the startup code of ASP.NET Core apps.

See the example · Permalink

M What files does dotnet build produce, and what are they for? concept

In bin/Debug/net10.0: the .dll with your IL, an .exe launcher on Windows, a .pdb with debug information, runtimeconfig.json naming the .NET version to use, and deps.json listing dependencies. They are rebuilt every time and never committed.

See the example · Permalink

Senior (6-9 yrs)​

S An app runs on your laptop but fails to start on the server. How do you check whether it is a .NET version problem? scenario

Read the app's runtimeconfig.json to see which framework and version it needs, then run dotnet --list-runtimes on the server. If the matching runtime is missing, install it, or publish the app self-contained so it carries its own runtime.

How to answer: Show a methodical check: what the app needs, what the server has, and the startup error message. Mention ASP.NET Core apps need the ASP.NET Core runtime, not just the base runtime.

See the example · Permalink

S How would you organize a .NET solution for a system with an API, shared logic, data access, and tests? design

One solution with projects in src (for example SchoolApp.Api, SchoolApp.Core, SchoolApp.Data) and tests. Core holds models and rules with no dependencies, Data references Core, and the API references both. Tests reference what they test.

How to answer: Explain the dependency direction and why: Core must not depend on databases or web frameworks, so it stays easy to test and reuse. Mention consistent naming and the .slnx format.

See the example · Permalink

Architect / Lead (10+ yrs)​

A Framework-dependent or self-contained deployment: how do you choose? design

Framework-dependent apps are small and use the runtime installed on the server, which the operations team patches. Self-contained apps carry their own runtime: larger, but independent of the server, and you must ship updates for security fixes yourself. Containers make this choice simpler, because the image includes the runtime.

How to answer: Compare size, patching responsibility, and control over the version. Tie the decision to how the organization deploys: managed servers, customer machines, or containers.

See the example · Permalink

Resources​

  • Code for this lesson: git tag lesson-30-dotnet-platform (code repository coming soon)
  • Files: src/SchoolApp.Console/Program.cs, library-assignment/030-library-welcome.cs
  • Video: coming soon

What's next​

Your first program prints fixed text. Next, it starts working with real school values: fees, marks, and dates, stored in variables of the right type. Lesson 31: Variables and data types

Want live sessions, code reviews, and interview preparation? Join the next batch at Sahasra Technologies.