Skip to main content

.NET Platform Fundamentals

Level: Beginner

ℹ️ What You'll Learn
  • What is .NET and why it exists
  • .NET Framework vs .NET Core vs .NET (modern)
  • How .NET code compiles and runs
  • CLR (Common Language Runtime) and MSIL
  • NuGet packages and dependencies
  • .NET project structure and csproj files
  • Different .NET versions and when to use them
ℹ️ Why Learn .NET Platform?

C# is a language. .NET is the platform that runs C# code. Understanding .NET means understanding how your code actually executes on computers, how packages work, and how to build production applications.

What is .NET?

.NET is a free, open-source platform for building applications.

Think of it this way:

  • Language: C# (what you code in)
  • Platform: .NET (what runs your code)
  • Framework: ASP.NET Core (web application framework)

Example: You write School Management API in C#. .NET runtime executes it.

The Evolution: .NET Framework → .NET Core → .NET

This is confusing for beginners. Let me clarify:

.NET Framework (2002-2023) — Old

First version of .NET. Windows-only. Older companies still use it.

.NET Framework 4.8 (last version)

Problems:

  • Only works on Windows
  • Heavy, large installation
  • Slow to update
  • Not open-source

.NET Core (2016-2020) — Transition

Microsoft's response. Cross-platform. Open-source.

.NET Core 3.1 (last version)

Improvements:

  • Works on Windows, Linux, Mac
  • Lightweight
  • Fast updates
  • Open-source

.NET 5+ (2020-Now) — Modern

Renamed to just ".NET". Unified platform.

.NET 5, 6, 7, 8 (current), 9 (preview)

Current standard:

  • Cross-platform
  • Modern, fast, secure
  • Regular updates (every year)
  • Industry standard

For this course: Use .NET 8 (stable, production-ready)

How .NET Works — Compilation Process

When you write C# code and run it:

C# Code (.cs file)
↓ (C# Compiler)
MSIL Code (.dll/.exe)
↓ (JIT Compiler at runtime)
Native Machine Code (CPU-specific)
↓ (Execution)
Running Application

Step 1: Compilation (C# Compiler)

Your C# code compiles to MSIL (Microsoft Intermediate Language).

MSIL is not native machine code. It's intermediate code that any CPU can understand (after one more step).

// C# Code
int total = 5 + 3;

Becomes MSIL:

ldc.i4.5 ; load 5
ldc.i4.3 ; load 3
add ; add them
stloc.0 ; store result

Step 2: Runtime Execution (JIT Compiler)

When your program runs, .NET's CLR (Common Language Runtime) takes MSIL and compiles it to native machine code.

This happens just-in-time (JIT) — right when you need it.

Advantages:

  • MSIL works on any OS (.NET installed there)
  • JIT optimizes for the specific CPU
  • Single codebase, multiple platforms

Example: School Management API

Developer writes: new SchoolRepository()
↓ (C# Compiler)
MSIL: newobj SchoolRepository
↓ (JIT at runtime)
Native: Create object at memory address 0x7FFF1234
↓ (Execution)
SchoolRepository instance runs

The CLR — Common Language Runtime

The CLR is like the engine that runs your code.

What CLR does:

  • Loads MSIL code
  • Compiles to native code (JIT)
  • Manages memory (garbage collection)
  • Handles exceptions
  • Enforces security

Why "Common"? Many languages compile to MSIL: C#, VB.NET, F#. All run on same CLR.

NuGet — Package Manager

NuGet is like App Store for code libraries.

What it solves: You need Entity Framework Core for your School Management API. You can:

Bad way (old): Download DLL from website, copy to project Good way (NuGet): dotnet add package Microsoft.EntityFrameworkCore

NuGet automatically downloads and installs the package and its dependencies.

Using NuGet

In Visual Studio:

Tools → NuGet Package Manager → Package Manager Console
Install-Package Microsoft.EntityFrameworkCore

Via CLI:

dotnet add package Microsoft.EntityFrameworkCore

NuGet stores packages in .csproj file (project file).

Project Structure

When you create a .NET project, you get this structure:

SchoolAPI/
├── bin/ → Compiled output (.dll files)
├── obj/ → Temporary build files
├── Properties/ → Version, settings
├── SchoolAPI.csproj → Project file (NuGet packages, configuration)
├── Program.cs → Entry point (Main method)
├── Controllers/ → API endpoints (ASP.NET Core)
├── Models/ → Data classes (Student, Teacher, etc.)
├── Data/ → Database access
└── appsettings.json → Configuration (database connection, etc.)

.csproj File (Project File)

This file defines your project:

<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
</ItemGroup>

</Project>

What it says:

  • Target framework: .NET 8.0
  • Uses Web SDK (ASP.NET Core)
  • Needs Entity Framework Core package version 8.0.0

.NET Versions — Which One to Use?

VersionReleasedStatusUse Case
.NET Framework 4.82019LegacyOld enterprise apps
.NET 5Nov 2020End of LifeDon't use
.NET 6Nov 2021LTSLong-term support
.NET 7Nov 2022End of LifeDon't use
.NET 8Nov 2023LTS (Current)Use this
.NET 9Nov 2024LatestBleeding edge

LTS = Long Term Support (3 years)

For learning: Use .NET 8

  • Stable, production-ready
  • Long support period
  • Industry standard
  • All features you need

How Code Executes — Simple Example

You write:

class Program
{
static void Main()
{
int result = Add(5, 3);
Console.WriteLine(result);
}

static int Add(int a, int b)
{
return a + b;
}
}

What happens:

  1. C# Compiler reads code → MSIL
  2. You run: dotnet run or dotnet .\SchoolAPI.dll
  3. .NET Runtime (CLR) starts
  4. CLR loads MSIL
  5. CLR JIT-compiles Main() to native code
  6. CPU executes native code
  7. Main() calls Add() → JIT-compiles Add() → executes
  8. Result: 8 printed, program exits

Memory management:

  • CLR allocates memory for result variable
  • After Main() finishes, CLR garbage collection frees memory
  • Developer doesn't manually manage memory (unlike C/C++)

Managed vs Unmanaged Code

Managed Code (C#, VB.NET)

  • Runs inside CLR
  • Automatic memory management
  • Type-safe
  • Security checks

Unmanaged Code (C, C++)

  • Runs directly on OS
  • Manual memory management
  • Faster but dangerous
  • Programmer responsible for cleanup

.NET is managed code platform. CLR takes care of memory.

.NET Compilation Modes

Debug Mode

dotnet build

Creates MSIL with debugging information. Slower, easier to debug.

Release Mode

dotnet build -c Release

Creates optimized MSIL. Faster, smaller, harder to debug.

Use Release for production deployment.

.NET Tools You Need

ToolPurpose
.NET SDKContains compiler, runtime, tools
Visual StudioIDE (development environment)
NuGetPackage manager
dotnet CLICommand-line tool
GitVersion control

Supported Languages on .NET

.NET supports languages that compile to MSIL:

  • C# — Primary language (what you'll use)
  • VB.NET — Visual Basic version of .NET
  • F# — Functional programming language
  • PowerShell — Scripting language

All run on same CLR, can call each other.

Why .NET for School Management System?

School API requirements:

  • REST API (ASP.NET Core) ✓
  • Database (Entity Framework Core + SQL Server) ✓
  • Authentication (built-in) ✓
  • Performance (optimized CLR) ✓
  • Cross-platform (Windows, Linux, Docker) ✓
  • Job market demand (India tech jobs) ✓

Common Misconceptions

Myth 1: ".NET only works on Windows"

  • Reality: .NET 5+ works on Windows, Linux, Mac

Myth 2: "C# and .NET are the same"

  • Reality: C# is language, .NET is platform

Myth 3: ".NET is slow"

  • Reality: JIT compilation makes .NET very fast

Myth 4: ".NET requires Visual Studio"

  • Reality: Works fine with VS Code + dotnet CLI

Myth 5: ".NET is only for web"

  • Reality: Desktop apps, mobile (MAUI), games (Unity), console apps

Quick Recap

ConceptWhat It Is
.NETPlatform for running applications
C#Programming language
CLRRuntime engine that executes code
MSILIntermediate code before execution
JITCompiler that converts MSIL to native code
NuGetPackage manager for libraries
.NET 8Current stable version
csprojProject configuration file
🎯 Interview Favourite

Q: How does .NET code compile and execute? Explain the role of CLR and MSIL.

Good Answer: "When I write C# code, the C# compiler first compiles it to MSIL (Microsoft Intermediate Language), which is platform-independent bytecode stored in DLL or EXE files. When the program runs, the .NET Runtime (CLR - Common Language Runtime) takes this MSIL code and uses a JIT (Just-In-Time) compiler to convert it to native machine code specific to the CPU at runtime. The CLR also handles memory management through garbage collection, so I don't have to manually free memory like in C++. This design allows the same MSIL code to run on Windows, Linux, or Mac without recompilation."

🤖Use AI to Learn Faster

Use ChatGPT, Claude, or Copilot to go deeper on .NET platform fundamentals. Try these prompts:

  • "Explain the difference between .NET Framework, .NET Core, and .NET 5+"
  • "What is MSIL and how is it different from native machine code?"
  • "What does the CLR do and why is it important?"
  • "How do I use NuGet to add packages to my .NET project?"

💡 Tip: After reading this article, paste your own code into AI and ask "What could go wrong here and why?" — fastest way to find edge cases and deepen understanding.

Next Article

-> SDK Setup and Installation

nexcoding.in