Skip to content
Happy Programming Guide
Start learning
C#

Introduction to C#

What C# is, what .NET provides, where the language is used, and your first program — plus how it compares with Java, Python and JavaScript.

A pen and an open notebook ready for notes

C# is a statically typed, object-oriented language built by Microsoft and run on .NET. It is used for web back ends, desktop applications, cloud services and games — Unity uses it as its scripting language. Since .NET became cross-platform it runs equally well on Windows, macOS and Linux, which removed the main reason people used to rule it out.

C# and .NET are different things#

C# is the language — the syntax you write. .NET is the platform it runs on: the runtime that executes your code, plus a large standard library covering collections, files, networking, JSON and much else.

The relationship is the same as Java to the JVM. You write C#, the compiler produces intermediate language, and the .NET runtime turns that into machine code as the program runs. Other languages target .NET too — F# and Visual Basic — but C# is by far the most used.

What people build with it#

Area Typical technology
Web back ends and APIs ASP.NET Core
Games Unity
Desktop applications WPF, WinUI, Avalonia, MAUI
Cloud and serverless Azure Functions, containers
Command-line tools the base library plus System.CommandLine
Cross-platform mobile .NET MAUI

It is particularly common in business and enterprise settings, which is worth knowing if you are weighing it up for employment reasons.

Installing and running#

Terminal
dotnet --version

Download the .NET SDK from Microsoft’s site if that command is not found. The SDK includes the compiler, the runtime and the dotnet tool.

Terminal
dotnet new console -n HelloApp
cd HelloApp
dotnet run

Three commands from nothing to a running program. For an editor, Visual Studio on Windows, or VS Code with the C# Dev Kit extension anywhere.

Your first program#

CSHARP
Console.Write("What is your name? ");
string? name = Console.ReadLine();

Console.Write("How old are you? ");
if (int.TryParse(Console.ReadLine(), out int age))
{
    Console.WriteLine($"Hello {name}, next year you will be {age + 1}.");
}
else
{
    Console.WriteLine("That was not a number.");
}

Modern C# allows this without a class wrapper — top-level statements. The older full form still appears everywhere and is what you will see inside larger projects:

CSHARP
using System;

namespace HelloApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello");
        }
    }
}

What the language looks like#

CSHARP
// Types are declared and checked at compile time
int count = 42;
double price = 12.99;
decimal money = 19.99m;        // decimal for currency
string name = "Ana";
bool ready = true;
var inferred = count * 2;      // still an int, just inferred

// Nullable types
string? maybeName = null;
int? maybeCount = null;

// Conditions
string grade = score switch
{
    >= 80 => "A",
    >= 70 => "B",
    _     => "F",
};

// Loops
foreach (var fruit in fruits) Console.WriteLine(fruit);
for (int i = 0; i < 5; i++) Console.WriteLine(i);

// Collections
var names = new List<string> { "Ana", "Sam" };
var ages = new Dictionary<string, int> { ["Ana"] = 34 };

// LINQ - querying collections
var adults = people.Where(p => p.Age >= 18)
                   .OrderBy(p => p.Name)
                   .ToList();

Classes and records#

CSHARP
public class Person
{
    public string Name { get; set; }
    public int Age { get; private set; }

    public Person(string name, int age)
    {
        Name = name;
        Age = age;
    }

    public bool IsAdult => Age >= 18;
    public void HaveBirthday() => Age++;
}
CSHARP
// A record - for data that is defined by its values
public record Point(double X, double Y);

var a = new Point(1, 2);
var b = new Point(1, 2);
Console.WriteLine(a == b);          // True - compares values
var moved = a with { X = 5 };       // copy with one change

That single record line replaces a constructor, two properties, equality, hashing and a readable ToString.

Static typing, and what it buys#

CSHARP
int count = "hello";      // compile error, before the program ever runs

The compiler catches type mistakes, so a whole category of bug never reaches run time. The cost is more to write and a compile step; the benefit is that large codebases stay manageable and your editor can autocomplete and refactor reliably.

Python and JavaScript check types as the code runs, so the same mistake surfaces only when that line executes — possibly in production.

How it compares#

C# Java Python JavaScript
Typing static static dynamic dynamic
Runs in a browser no no no yes
Learning curve moderate moderate gentle moderate
Strongest in business apps, games enterprise, Android data, scripting web front ends

C# and Java are close relatives — knowing one makes the other largely readable. C# has moved faster in recent years, picking up records, pattern matching, nullable reference types and top-level statements.

What to learn, in order#

  1. Types, variables and string interpolation
  2. Conditions and loops
  3. Methods — parameters, return values, overloads
  4. Collections — lists, dictionaries, arrays
  5. Classes and objects — properties, constructors, inheritance
  6. LINQ — it replaces a great deal of loop writing
  7. Exceptions and the TryParse pattern
  8. async and await

Then pick a direction: ASP.NET Core for web work, Unity for games, or MAUI for applications.

Questions people ask#

Do I need Windows?

No. .NET runs on macOS and Linux, and VS Code works everywhere. Only some older desktop frameworks are Windows-only.

What is the difference between .NET Framework and .NET?

.NET Framework is the old Windows-only version, still maintained for existing applications. Modern .NET — version 5 and later — is cross-platform and is what new projects use.

Is C# good for beginners?

It is a reasonable first language, though there is more to learn before your first program runs than in Python. The type system helps once projects grow beyond a single file.

Is Unity a good reason to learn it?

Yes — Unity scripting is C#, and everything you learn transfers to ordinary C# development. It is one of the more motivating ways in.

Where to go next#

C# basics, with the syntax you will use dailyRead next

Keep reading

C#

C# Events and Delegates

What a delegate is, how events build on them, Action and Func, and the two mistakes that cause memory leaks and null…

5 min read

C#

C# Design Patterns

The design patterns that earn their place in C#: strategy, factory, repository, decorator, observer and options — with the language features that…

4 min read

Keep going — pick your next guide

The fastest way to improve is to read one guide, then build the thing it describes. Start with the basics, or jump straight to a project.

Ask a question or share what worked

Your email address will not be published. Required fields are marked *