backendgym backendgym · reps Sign in with GitHubSign in
← Reps
C# Warm-up

C# · Reading Other People's Code

Read C# somebody else wrote, run it, and explain why it prints what it prints: struct copies, closures, deferred queries, disposal and equality.

csharp-reading / README.md

Each rep is a program that already exists at reps/NN/Program.cs, and dotnet run --project reps/NN compiles it, runs it and prints the output. You only read the first six. You edit the last one. You work in a copy of the set's starter, a repository of your own, and installing the .NET 8 SDK (or running it in a container) is its first task.

You need enough C# to read a class, a loop and a method call. You don't need to be able to write them from scratch, and this set won't ask you to. It trains reading code you didn't write and saying what it actually does. That's a different skill from writing it, and once a machine writes the first draft it's the one you use more.

Every rep works the same way. Read the program, run it, and look at the output, which the statement prints too. The work is explaining it: each line, and why it isn't what a quick read suggests. The questions on the bench after each rep are where you say it.

Struct copies, closure capture, deferred execution, synchronization contexts, deterministic disposal, and which == the compiler picks: none of it is explained here. Looking it up when a rep hits it is how the model gets built.

Reps

Do them in order. Each rep assumes the ones before it.

  1. 01 Where the copy happened
  2. 02 Two loops, one difference
  3. 03 When the query runs
  4. 04 The deadlock that isn't there
  5. 05 Two handles, one dispose
  6. 06 Eight comparisons
  7. 07 The one that compiles and lies