C# Introduction

What C# is, how it relates to .NET, installing the .NET SDK, and top-level statements hello world.

What is C#?

C# (pronounced "C sharp") is a modern, type-safe, object-oriented programming language created by Microsoft (led by Anders Hejlsberg) and first released in 2000 alongside the original .NET Framework. It's the primary language of the .NET ecosystem — used for web APIs, desktop apps, cloud services, and game development (via Unity).

C#
Console.WriteLine("Hello, World!");

C# and .NET — how they relate

.NET is the platform: a runtime, a set of standard libraries, and a set of tools. C# is the language you write most .NET code in (F# and VB.NET also target .NET, but C# is by far the dominant choice).

Since .NET 5 (2020), Microsoft unified what used to be several separate platforms — the Windows-only .NET Framework, the cross-platform .NET Core, and Xamarin/Mono — into one modern, cross-platform ".NET" that runs on Windows, macOS, and Linux. When people say ".NET" today (.NET 8, .NET 9), they mean this unified, cross-platform runtime — not the legacy Windows-only .NET Framework.

Code compiles to an intermediate language called CIL (Common Intermediate Language), which the CLR (Common Language Runtime) executes — conceptually very similar to how Java compiles to bytecode for the JVM. This is what gives .NET its cross-platform reach and automatic memory management (garbage collection).

Installing the .NET SDK

Download the SDK (not just the runtime — the SDK includes the compiler and CLI tools) from dotnet.microsoft.com.

Verify the install:

Bash
dotnet --version
# 8.0.401

Creating and running your first project

Bash
dotnet new console -n HelloWorld
cd HelloWorld
dotnet run
# Hello, World!

dotnet new console scaffolds a new console project, including a .csproj file (the project's configuration — target framework, dependencies) and a Program.cs entry-point file.

Top-level statements

Since C# 9 (2020), a console app's entry point no longer needs an explicit class Program and static void Main wrapper — Program.cs can just be:

C#
Console.WriteLine("Hello, World!");

var name = "World";
Console.WriteLine($"Hello, {name}!");

This compiles to exactly the same thing as the traditional, more verbose form:

C#
using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello, World!");
    }
}

Top-level statements are purely a syntax convenience for the entry-point file — every other file in a real project still uses ordinary classes. They're commonly used for small scripts, quick prototypes, and tutorials (including this one), and are the default template dotnet new console now generates.

Real-world example

Stack Overflow's original backend, most of the enterprise software Microsoft itself ships, a huge share of banking and insurance backends, and virtually every game built with the Unity engine all run on C#. Azure's own SDKs and much of Azure's internal tooling are also written in C#.

Common mistakes

  • Installing only the .NET runtime instead of the SDK — the runtime alone can't compile or scaffold new projects; you need the SDK for development.
  • Assuming ".NET Framework" and ".NET" (post-.NET 5) are the same thing — .NET Framework is the legacy, Windows-only platform, now in maintenance mode; modern .NET is the actively developed, cross-platform successor.
  • Forgetting that top-level statements are an entry-point-only convenience — you still define ordinary classes with class/methods everywhere else in a real application.

Interview questions

Q: What's the difference between the CLR and the .NET SDK? The CLR (Common Language Runtime) is the execution engine that runs compiled .NET code (CIL) — it handles memory management, garbage collection, and JIT compilation to native machine code. The .NET SDK is the full development toolkit: the compiler, the dotnet CLI, project templates, and the CLR/runtime needed to actually run what you build.

Q: Is C# only for Windows development? No — since .NET 5 unified the platform, C# and .NET run natively on Windows, macOS, and Linux, and are commonly used for cross-platform web APIs (ASP.NET Core), cloud services, and cross-platform desktop apps (via .NET MAUI or Avalonia). The Windows-only era ended with the legacy .NET Framework.