What is C# and .NET?
🎯 What You'll Learn
- The history of C# and why Microsoft created it
- What .NET actually is (runtime, libraries, ecosystem)
- The difference between .NET Framework, .NET Core, and modern .NET
- How C# code becomes a running program (compilation pipeline)
- Key terminology: CLR, IL, JIT, SDK, Runtime
- How to set up your development environment
A Brief History
To understand C# and .NET, we need to travel back to the late 1990s. Microsoft was watching the explosive growth of Java—a language that promised "write once, run anywhere." Java code could run on Windows, Mac, Linux, and more, thanks to the Java Virtual Machine (JVM).
Microsoft needed an answer. They wanted a modern, object-oriented language that could:
- Compete with Java's productivity and safety
- Work seamlessly with Windows and their growing web technologies
- Be easier to use than C++, which was powerful but notoriously complex
- Support the future of web services and distributed computing
The result was a two-part solution announced in 2000:
- C# (pronounced "C-sharp") — A new programming language
- .NET Framework — A platform for running C# (and other languages)
The lead architect of C# was Anders Hejlsberg, who had previously created Turbo Pascal and was the chief architect of Delphi—two of the most beloved development tools of their era. His experience shows in C#'s design: it's pragmatic, readable, and developer-friendly.
The name comes from music notation, where a "sharp" (♯) raises a note by a half step. It's a play on C++, where "++" is an operator that increments a value. So C# is symbolically "C++ incremented" or "C++ improved." The # symbol was chosen because it's easier to type than ♯.
Understanding .NET: The Platform
Here's a critical distinction that confuses many beginners: C# is a language; .NET is a platform. They're closely related but different things.
.NET consists of several key components:
1. The Common Language Runtime (CLR)
The CLR is the heart of .NET. It's the "virtual machine" that actually runs your code. When you hear ".NET Runtime," this is what people usually mean.
The CLR provides crucial services:
- Memory Management
- The CLR automatically allocates and frees memory for your objects. You don't need to manually manage memory like in C or C++. This is called garbage collection.
- Type Safety
- The CLR enforces that you use data types correctly. You can't accidentally treat a number as text or access memory you shouldn't.
- Exception Handling
- When errors occur, the CLR provides a structured way to catch and handle them instead of your program crashing mysteriously.
- Security
- The CLR enforces security boundaries, preventing malicious code from accessing system resources it shouldn't.
- JIT Compilation
- The CLR compiles your intermediate code to machine code right before execution, optimizing it for the specific computer it's running on.
2. The Base Class Library (BCL)
The Base Class Library is a massive collection of pre-written code that you can use in your programs. Why write code to read a file, make a web request, or format a date when Microsoft has already written (and tested) that code for you?
The BCL includes:
- System.IO — File and stream operations
- System.Collections — Lists, dictionaries, queues, stacks
- System.Net — Networking and HTTP
- System.Text — String manipulation, encoding, regular expressions
- System.Threading — Parallel and concurrent programming
- System.Linq — Querying data (we'll cover this extensively)
- ...and hundreds more
When you write a C# program, you're constantly using the BCL, often without realizing it.
Even something as simple as Console.WriteLine("Hello") uses the BCL's
System.Console class.
3. The SDK (Software Development Kit)
The .NET SDK is what you install on your computer to develop .NET applications. It includes:
- The C# compiler
- The runtime (CLR)
- The base class libraries
- Command-line tools (
dotnetCLI) - Project templates
When you "install .NET," you're typically installing the SDK.
4. The Runtime (Standalone)
The .NET Runtime is a smaller package that only includes what's needed to run .NET applications (not develop them). This is what you'd install on a server that needs to host your application but where no development happens.
SDK = Everything for development (includes Runtime)
Runtime = Only what's needed to run apps
As a developer, always install the SDK. The runtime is for production servers
or end-user machines.
The .NET Evolution: A Confusing History Made Clear
One of the most confusing things about .NET is its versioning history. Let me clarify this once and for all, because you'll encounter these terms in the wild.
.NET Framework (2002-2019) — The Original
The original .NET Framework ran only on Windows. For almost two decades, if you wanted to run C# code on Linux or Mac, you were out of luck (mostly).
.NET Framework versions went from 1.0 up to 4.8. Many enterprise applications still run on .NET Framework 4.8, and Microsoft continues to support it—but no new features are being added.
.NET Core (2016-2020) — The Revolution
In 2016, Microsoft did something remarkable: they rewrote .NET from scratch and made it open-source and cross-platform. This was called .NET Core.
.NET Core could run on Windows, Linux, and macOS. It was faster, more modular, and designed for modern cloud and container workloads. Versions went from 1.0 to 3.1.
.NET 5, 6, 7, 8... (2020-Present) — The Unification
In 2020, Microsoft unified everything under the simple name ".NET" (dropping both "Framework" and "Core"). They skipped version 4 to avoid confusion with .NET Framework 4.x.
| Version | Release | Support Type | Notes |
|---|---|---|---|
| .NET 5 | Nov 2020 | Standard (ended) | First unified .NET |
| .NET 6 | Nov 2021 | LTS (ended Nov 2024) | Long-term support |
| .NET 7 | Nov 2022 | Standard (ended) | Short-term support |
| .NET 8 | Nov 2023 | LTS (until Nov 2026) | ← We'll use this! |
| .NET 9 | Nov 2024 | Standard | Latest features |
LTS (Long-Term Support) versions are supported for 3 years and are recommended for production applications. Standard versions get 18 months of support and contain the newest features.
For this guide and your professional work, use .NET 8. It's the current LTS version, meaning it's stable, well-supported, and what most companies are adopting for new projects. All examples in this guide will use .NET 8.
What About ASP.NET?
You might be wondering where ASP.NET fits in. Here's the quick breakdown:
- ASP.NET (Original)
- The web framework that ran on .NET Framework. Included Web Forms, MVC, Web API, and SignalR. Windows-only.
- ASP.NET Core
- The modern, cross-platform rewrite of ASP.NET that runs on .NET Core / .NET 5+. This is what we'll be learning. It's faster, more flexible, and the future of .NET web development.
When we say "ASP.NET Core Mastery," we mean building web applications using ASP.NET Core on modern .NET (version 8 in our case).
How C# Code Becomes a Running Program
Let's trace the journey from the code you write to the program that runs. Understanding this process helps demystify error messages and debugging.
Step 1: You Write Source Code
You create files with the .cs extension containing C# code:
using System;
class Program
{
static void Main()
{
Console.WriteLine("Hello, World!");
}
}
This is human-readable text. The computer can't run it yet.
Step 2: The C# Compiler Creates IL
When you build your project, the C# compiler (csc.exe or Roslyn)
reads your source code and produces Intermediate Language (IL),
also called MSIL or CIL.
IL is a CPU-independent instruction set. It's not machine code yet, but it's much lower-level than C#. Here's roughly what our "Hello World" looks like in IL:
.method private hidebysig static void Main() cil managed
{
.entrypoint
.maxstack 1
ldstr "Hello, World!"
call void [System.Console]System.Console::WriteLine(string)
ret
}
You'll never need to write or read IL directly, but knowing it exists helps you understand what's happening under the hood.
The IL code is packaged into an assembly—either a
.dll (Dynamic Link Library) or .exe (Executable) file.
Step 3: The CLR JIT-Compiles to Machine Code
When you run your program, the CLR's JIT (Just-In-Time) compiler converts the IL to native machine code for your specific processor.
Why not compile directly to machine code like C++? Because IL enables powerful features:
- Cross-platform: The same IL runs on Windows, Linux, and Mac—the JIT produces the right machine code for each
- Optimization: The JIT can optimize for the specific CPU at runtime
- Security: The CLR can verify IL is safe before executing it
- Language interop: C#, F#, and VB.NET all compile to IL, so they can work together seamlessly
The Full Picture
| Stage | Input | Output | When |
|---|---|---|---|
| 1. Compilation | Source code (.cs) | IL in assembly (.dll/.exe) | Build time |
| 2. JIT Compilation | IL | Machine code | Runtime (first execution) |
| 3. Execution | Machine code | Program behavior | Runtime |
C# as a Language: Key Characteristics
Now that you understand the platform, let's look at C# itself. What kind of language is it?
Statically Typed
In C#, every variable has a specific type, and that type is checked at compile time. This catches many errors before your code even runs.
int age = 25; // age is an integer
string name = "Akwasi"; // name is text
age = "twenty-five"; // ERROR! Can't assign text to an integer
Compare this to Python (dynamically typed), where the same variable can hold different types at different times. Static typing adds safety but requires you to be explicit about what kind of data you're working with.
Object-Oriented
C# is built around the concept of objects—bundles of data and behavior. Everything in C# is either an object or belongs to an object. We'll explore this deeply in the OOP section.
Memory-Managed
Unlike C or C++, you don't manually allocate and free memory. The garbage collector handles this automatically. This prevents entire categories of bugs (memory leaks, use-after-free) at the cost of occasional garbage collection pauses.
Modern and Evolving
C# is actively developed. New versions add features like pattern matching, records, nullable reference types, and more. The language has evolved dramatically from version 1.0 to the current version (12 as of .NET 8), always staying modern and competitive.
Setting Up Your Development Environment
Let's get your computer ready for C# development. We'll install Visual Studio 2022, which includes everything you need.
Installing Visual Studio 2022
Visual Studio is Microsoft's flagship IDE (Integrated Development Environment) for .NET development. The Community Edition is free for individuals, students, and small teams. It provides the best C# development experience with IntelliSense, debugging, refactoring tools, and seamless integration with .NET.
Follow these steps:
- Go to visualstudio.microsoft.com/downloads
- Download Visual Studio 2022 Community (the free version)
-
Run the installer. When prompted to select workloads, check:
- ASP.NET and web development (essential for our goals)
- .NET desktop development (useful for console apps and learning)
- Click Install and wait (this may take a while—it's a large download)
- Once installed, launch Visual Studio and sign in with a Microsoft account (or skip)
Verifying the Installation
Let's confirm everything is working by checking the .NET SDK version. Open a Command Prompt or PowerShell and type:
dotnet --version
You should see output like:
8.0.100
The exact version may differ, but as long as it starts with 8., you're
using .NET 8.
You can also see all installed SDKs:
dotnet --list-sdks
Creating Your First Project (Quick Test)
Let's create a quick project to verify everything works. We'll do this properly in later sections, but here's a quick test:
- Open Visual Studio 2022
- Click Create a new project
- Search for "Console" and select Console App (make sure it says "C#" and not "Visual Basic")
- Click Next
- Name your project
HelloWorldand choose a location - Click Next
- Ensure .NET 8.0 is selected in the Framework dropdown
- Click Create
Visual Studio will create a project with a single file containing:
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
Press F5 (or click the green "Start" button). A console window should appear showing "Hello, World!" — and then immediately close.
To keep the console window open after the program finishes, press Ctrl+F5 instead of F5. This runs without the debugger and adds a "Press any key to continue" prompt.
Congratulations! You've just compiled and run your first C# program. 🎉
Understanding the Modern C# Template
You might have noticed the code was surprisingly short—just one line. That's because .NET 6+ introduced top-level statements, which remove the ceremonial boilerplate for simple programs.
Behind the scenes, the compiler wraps your code in the traditional structure. These two programs are equivalent:
Console.WriteLine("Hello, World!");
using System;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}
}
We'll use top-level statements for simple examples (they reduce noise while learning), but you'll also learn the traditional structure because real-world applications use it.
Key Terminology Reference
Here's a quick reference for the terms we've covered. Bookmark this for later!
| Term | Definition |
|---|---|
| C# | A modern, object-oriented programming language created by Microsoft |
| .NET | A platform/ecosystem for building applications (includes runtime, libraries, tools) |
| CLR | Common Language Runtime — the virtual machine that executes .NET code |
| IL | Intermediate Language — the bytecode that C# compiles to |
| JIT | Just-In-Time compiler — converts IL to machine code at runtime |
| SDK | Software Development Kit — everything needed to develop .NET apps |
| Runtime | The subset needed to run (not develop) .NET apps |
| BCL | Base Class Library — the built-in library of useful code |
| Assembly | A compiled unit of code (.dll or .exe file) |
| LTS | Long-Term Support — versions supported for 3 years |
Key Takeaways
- C# is a language; .NET is the platform that runs it
- The CLR provides memory management, type safety, and JIT compilation
- The BCL provides thousands of ready-to-use classes
- Modern .NET is cross-platform and open-source
- C# code compiles to IL, which the JIT converts to machine code
- Use .NET 8 (LTS) for new projects
- Visual Studio 2022 Community is free and provides the best C# experience
You now have a solid understanding of the C#/.NET ecosystem and a working development environment. In the next section, we'll start writing real code—beginning with variables and data types.
What's Next?
In the next section, Variables and Data Types, we'll learn how to
store and manipulate data in C#. You'll understand the difference between int,
string, bool, and other fundamental types—the building blocks
of every program.