Part 0 · 1 chapters · ~8 min

Basics

Installing the .NET SDK, dotnet new and dotnet run, top-level programs, types and variables, string interpolation, records and classes, switch expressions, collections and LINQ, methods and lambdas, namespaces and projects, and a first program.

1

First code

code
// Program.cs (dotnet new console; dotnet run) on .NET 10 here
record Transfer(string Id, long AmountKobo, Channel Channel, Status Status);
enum Channel { App, Ussd }
enum Status { Pending, Completed, Failed }

static long Fee(long amount, Channel ch) => (ch, amount) switch
{
    (Channel.Ussd, _) => 2_000,
    (_, <= 500_000) => 1_000,
    (_, <= 5_000_000) => 2_500,
    _ => 5_000,
};

var total = transfers.Where(t => t.Status == Status.Completed).Sum(t => t.AmountKobo + Fee(t.AmountKobo, t.Channel));
Console.WriteLine($"₦{total / 100:N0}.{total % 100:D2}");
C# IN SIX IDEAS
a modern language on a managed runtime
top-level programsA file can just containstatements; no class Main needed.recordsrecord Transfer(...): immutabledata with value equality.pattern matchingswitch expressions on types,properties, tuples.LINQQuery collections and databaseswith the same operators.async/awaitAsynchronous code that reads likesynchronous code.nullable referencesstring vs string? checked by thecompiler.
swipe the figure sideways, or tap expand for full screen
1/4
modern C#
Recent C# versions removed much ceremony: top-level statements, file-scoped namespaces, records and target-typed new.
less ceremonyrecords for data