Skip to main content
C# beginner Lesson 1 of 25

Introduction to C#

Learn what C# is, how the .NET ecosystem works, and where C# is used in the real world.

What is C#?

C# (pronounced “C sharp”) is a statically typed, object-oriented programming language developed by Microsoft. It was first released in 2000 as part of the .NET Framework and has evolved into one of the most feature-rich languages in active use today. Being statically typed means the compiler catches type errors before your program runs, giving you faster feedback and safer code. C# draws from C, C++, and Java but adds features those languages lack — nullable reference types, pattern matching, records, async/await, and LINQ among them.

// A minimal C# program (top-level statements, .NET 6+)
// No class or Main method needed — the compiler wraps it for you
Console.WriteLine("Hello, C#!");

Before .NET 6 you needed a class and a Main method. You may still encounter this style in older codebases:

using System;

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

Both are valid. Top-level statements are the recommended style for new projects because they reduce boilerplate and let you focus on your actual code.

The .NET Ecosystem

.NET is the open-source, cross-platform runtime and SDK that C# runs on. Understanding the platform helps you make sense of the tooling, package ecosystem, and version numbers you’ll encounter. The name has changed over the years:

NameYearsNotes
.NET Framework2002–presentWindows-only, still used for legacy apps
.NET Core2016–2020Cross-platform rewrite
.NET 5+2020–presentUnified platform, replaces both

When you install .NET today you get:

  • CLR (Common Language Runtime) — the virtual machine that runs compiled IL code
  • BCL (Base Class Library) — thousands of built-in types (collections, I/O, networking, crypto)
  • dotnet CLI — build, run, test, and publish from the terminal
  • NuGet — the package manager (like npm for JavaScript)
# Check your installed version
dotnet --version

# Create a new console project
dotnet new console -n MyApp

# Run it
cd MyApp && dotnet run

Where C# is Used

Enterprise Applications

C# is the dominant language for Windows enterprise software. The ASP.NET Core framework powers millions of production APIs and web apps. Its combination of strong typing, rich tooling, and performance makes it a natural fit for large teams building complex systems.

// ASP.NET Core minimal API — a full HTTP server in a few lines
// This runs cross-platform and handles production-scale traffic
var app = WebApplication.Create(args);
app.MapGet("/", () => "Hello from ASP.NET Core!");
app.Run();

Game Development

Unity — the world’s most widely used game engine — uses C# as its scripting language. Every Unity game script is a C# class inheriting from MonoBehaviour. This means millions of game developers write C# daily, making it one of the most-used languages in the gaming industry.

using UnityEngine;

// MonoBehaviour is the base class for all Unity scripts
public class PlayerController : MonoBehaviour
{
    public float speed = 5f;

    // Update is called once per frame by the Unity engine
    void Update()
    {
        float h = Input.GetAxis("Horizontal");
        transform.Translate(Vector3.right * h * speed * Time.deltaTime);
    }
}

Cloud and Azure

Azure Functions, Azure Service Bus consumers, and Azure SDK clients are all written in C#. Microsoft’s own cloud tooling is built on it, which means C# developers get first-class support and the latest features before other languages.

// Azure Function triggered by HTTP — serverless C# in the cloud
[Function("HttpTrigger")]
public IActionResult Run(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequest req)
{
    return new OkObjectResult("Azure Function response");
}

Desktop Applications

WPF (Windows Presentation Foundation) and WinForms handle Windows desktop apps. .NET MAUI extends this to macOS, iOS, and Android from a single codebase, letting you reuse business logic across platforms.

CLI Tools and Automation

The dotnet tool ecosystem lets you distribute cross-platform CLI tools written in C#. The dotnet CLI itself is written in C#, which is a testament to the language’s suitability for developer tooling.

Why C# Stands Out

Understanding what makes C# distinctive helps you appreciate the decisions behind its design and write more idiomatic code.

Nullable reference types give you opt-in null safety at compile time, eliminating whole categories of NullReferenceException bugs. Enable it in your project file and the compiler will warn you whenever you might dereference null.

Pattern matching lets you test a value’s shape, type, and content in one expression. It is more expressive than chains of if/else and rivals what functional languages offer.

Records are immutable data types with value equality baked in. Two records with the same data are equal by default, which is exactly what you want for DTOs and domain value objects.

LINQ (Language Integrated Query) lets you query any collection with a SQL-like syntax directly in C#. It works on in-memory lists, databases, XML, and anything else you plug in.

First-class asyncasync/await was pioneered in C# before most other mainstream languages adopted it. The model is composable, cancellable, and integrates seamlessly with the rest of the language.

// Records, pattern matching, and LINQ working together
record Product(string Name, decimal Price, string Category);

var products = new List<Product>
{
    new("Widget", 9.99m, "Tools"),
    new("Gadget", 49.99m, "Electronics"),
    new("Doohickey", 4.99m, "Tools"),
};

// Pattern matching inside a LINQ Where — expressive and readable
var cheapTools = products
    .Where(p => p is { Category: "Tools", Price: < 10m })
    .OrderBy(p => p.Price)
    .ToList();

foreach (var p in cheapTools)
    Console.WriteLine($"{p.Name}: ${p.Price}");

Next Steps

The best way to learn C# is to write code. Install the .NET SDK (covered in the next tutorial), create a console project, and experiment. The language has excellent IntelliSense support in VS Code and Visual Studio, so you’ll get helpful feedback as you type.

Frequently Asked Questions

Is C# only for Windows?
No. Since .NET Core (now just .NET), C# runs on Windows, Linux, and macOS. You can build cross-platform CLIs, web servers, and desktop apps.
What is the difference between .NET and C#?
C# is the programming language. .NET is the platform — it includes the runtime (CLR), base class libraries, and tools like the dotnet CLI. C# compiles to IL (Intermediate Language) that the CLR executes.
Should I learn C# or Java first?
Both are similar in syntax and concepts. C# has more modern language features (records, pattern matching, nullable reference types) and a cleaner async story. If your goal is Microsoft/Azure/game dev, start with C#.