C# Tutorial

Introduction to C#

Why C#, .NET, and your first Hello World program

What is C#?

C# (pronounced "C-Sharp") is a modern, object-oriented, and type-safe programming language developed by Microsoft. It runs on the .NET framework and is the language of choice for building Windows apps, enterprise software, and games using the Unity engine.
csharp
using System;

class Program {
    static void Main() {
        Console.WriteLine("Hello, Nocturnal Codex!");
    }
}

Why Choose C#?

  1. Versatility: Use it for Web (ASP.NET), Mobile (MAUI), Desktop (WPF/WinForms), and Games (Unity).
  2. Productivity: Modern features like LINQ, Async/Await, and Pattern Matching make coding fast and expressive.
  3. Safety: Strong typing and automatic memory management (Garbage Collection) prevent many common bugs.
  4. Ecosystem: Backed by Microsoft and a massive community, with the world-class Visual Studio IDE.

The .NET Ecosystem

Wait! C# doesn't run in a vacuum. It runs on .NET, which provides:
  • Runtime (CLR): Handles memory, security, and compilation (JIT).
  • Class Libraries: Thousands of built-in types for everything from JSON to Networking.
  • SDK & CLI: Tools for building and running your apps (dotnet build, dotnet run).

C# Evolution

C# moves fast! Every year, a new version is released with "Quality of Life" improvements. Modern C# (version 10, 11, 12+) is much more concise and powerful than the older versions you might see in legacy codebases.
[!TIP] Use the dotnet CLI. It's the modern, cross-platform way to manage your C# projects on Windows, macOS, and Linux.

Summary

FeatureDescription
CreatorAnders Hejlsberg (Microsoft)
ParadigmObject-Oriented, Component-Oriented
MemoryGarbage Collected
ToolingVisual Studio, VS Code, JetBrains Rider
Framework.NET (Open Source, Cross-Platform)
SpeedHigh performance (Near-native with JIT/AOT)
Best ForEnterprise, Web Backends, Game Dev (Unity)
LogicClean, structured, and highly readable
SafetyPrevents null pointer and memory corruption bugs
ModernRecords, Pattern Matching, and Primary Constructors
BinaryCompiles to Intermediate Language (IL), then to Machine Code
StandardECMA-334 and ISO/IEC 23270