Introduction

What .NET and C# are, how one compiles into the other, and what you will be able to build by the end of this course.

SyntaxConsole.WriteLine(string? value)

.NET is two things that ship together. One is a runtime: a program whose job is to run your program. The other is a large set of libraries: ready-made code for text, files, networking, dates and much more.

C# is the language you type. You write it in text files whose names end in .cs. A compiler reads those files and translates them into an assembly: a file ending in .dll that holds instructions in a format called IL, short for Intermediate Language. The runtime loads that assembly and executes it. So C# is what you write, and .NET is what runs the result.

Why this pair is used for web services

A web service is a program that waits for requests arriving over a network and sends answers back. .NET includes ASP.NET Core, a set of libraries built for that job. The compiler catches many mistakes before the program ever starts. The runtime stays fast under steady load. The same code runs on Windows, macOS and Linux.

Where this course ends

By the last stage you will have written an HTTP API that stores data in a PostgreSQL database, checks who the caller is, is covered by automated tests, runs inside a container, and is deployed on Kubernetes. Each stage adds one layer on top of the last.

Two version numbers

This course covers .NET 10 for the runtime and libraries, and C# 14 for the language. They are numbered separately and both numbers matter.

Example

Example · csharp
// This file is C#. A compiler turns it into an assembly: a .dll file.
// The .NET runtime then loads that assembly and executes it.

// Console is a type from the .NET libraries.
// WriteLine prints one line of text and moves to the next line.
Console.WriteLine("C# is the language you write.");
Console.WriteLine(".NET is the runtime and the libraries.");

// Statements run in order, top to bottom. The semicolon ends a statement.
Console.WriteLine("This course ends with a service on Kubernetes.");

// Output:
// C# is the language you write.
// .NET is the runtime and the libraries.
// This course ends with a service on Kubernetes.

When to use it

  • Deciding whether .NET fits a new HTTP service that has to run on Linux.
  • Reading an unfamiliar C# repository and telling language features apart from library calls.
  • Explaining why a .dll copied out of bin/ will not start on a machine with no .NET installed.

More examples

The same program written out in full

The short form and the long form are the same program. The short form is called top-level statements; the compiler generates the class and the entry point for you. Read the long form whenever you open someone else's older project, because that is the shape you will see there.

Example · csharp
// Every C# program has one entry point: a method the runtime calls first.
// Here it is written by hand. The three-line version above is a shorthand
// for exactly this, and both compile to the same program.
namespace Intro;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("C# is the language you write.");
        Console.WriteLine(".NET is the runtime and the libraries.");
        Console.WriteLine("This course ends with a service on Kubernetes.");
    }
}

// Output:
// C# is the language you write.
// .NET is the runtime and the libraries.
// This course ends with a service on Kubernetes.

Compiling is a separate step from running

Use this when you want to see that the .dll is a real file on disk rather than something hidden. It also shows why a change you forgot to rebuild has no effect: the .dll is still the old one.

Example · bash
dotnet new console -o Intro   # create a project folder named Intro
cd Intro
dotnet build                  # compile only: C# in, Intro.dll out

# The compiled assembly now sits in bin/Debug/net10.0 next to
# Intro.deps.json, Intro.runtimeconfig.json, a debug file Intro.pdb,
# and a small launcher program named Intro (Intro.exe on Windows).

Running an assembly the runtime already has

This is how a .NET program is started on a server: something hands the runtime a .dll. Reach for it when you want to prove that the build output alone, with no source code present, is enough to run the program.

Example · bash
# The dotnet command can run a compiled assembly directly.
dotnet bin/Debug/net10.0/Intro.dll
# C# is the language you write.
# .NET is the runtime and the libraries.
# This course ends with a service on Kubernetes.

Discussion

  • Be the first to comment on this lesson.