$ cd ../ (all courses)

C#

Modern, statically typed, runs on .NET. Powers games, web, enterprise.

⚠ pattern-based checks (code is analyzed, not compiled)

About C#

C# is a modern, object-oriented language by Microsoft, running on .NET. It's used for Unity games, ASP.NET web apps, desktop apps, and more. NOTE: Code is checked by pattern matching, not compiled. Focus on idiomatic C#.

Quick-reference cheat sheet
// C# cheat-sheet
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    static void Main() {
        int x = 42;
        string name = "Ada";
        bool ok = true;

        Console.WriteLine($"Hello, {name}!");

        if (x > 0) Console.WriteLine("positive");

        for (int i = 0; i < 5; i++) Console.WriteLine(i);

        var nums = new List<int> { 1, 2, 3 };
        nums.Add(4);

        string line = Console.ReadLine();
        int n = int.Parse(line);
    }

    static int Add(int a, int b) => a + b;
}

// Class with properties
class Person {
    public string Name { get; set; }
    public int Age { get; set; }
}

// LINQ
var evens = nums.Where(n => n % 2 == 0).ToList();
var sum = nums.Sum();

// Records (C# 9+)
public record Point(int X, int Y);

Tasks

  1. 01
    Hello, World!
    Console.WriteLine the greeting.
    intro
  2. 02
    Typed variables
    Declare an int, a string, and a bool.
    intro
  3. 03
    var keyword
    Use var for type inference.
    intro
  4. 04
    if / else
    Print whether a number is positive, zero, or negative.
    easy
  5. 05
    switch expression
    Use the modern switch expression.
    easy
  6. 06
    For loop
    Print 1..10 with a for loop.
    easy
  7. 07
    foreach over array
    Iterate an int[] with foreach.
    easy
  8. 08
    Define a method
    Define static int Add(int a, int b).
    easy
  9. 09
    String interpolation
    Interpolate two values.
    easy
  10. 10
    List<int>
    Create a List<int>, add 3 numbers, print the count.
    medium
  11. 11
    Dictionary<string,int>
    Build a string→int dictionary.
    medium
  12. 12
    LINQ Where
    Use LINQ Where to filter even numbers.
    medium
  13. 13
    LINQ Select
    Use Select to project squares.
    medium
  14. 14
    LINQ Sum / Average
    Aggregate a sequence.
    medium
  15. 15
    Define a Person class
    Class Person with Name and Age properties.
    medium
  16. 16
    Constructor
    Add a constructor to a class.
    medium
  17. 17
    Inheritance
    Subclass Animal with Dog.
    hard
  18. 18
    Interface
    Define interface IShape with double Area().
    hard
  19. 19
    Abstract class
    Abstract Shape class with abstract Area().
    hard
  20. 20
    Generic method
    Define static T First<T>(T[] arr).
    hard
  21. 21
    Nullable types
    Use int? and the ?? operator.
    medium
  22. 22
    try / catch
    Catch a FormatException.
    medium
  23. 23
    Lambda expression
    Assign a Func<int,int,int>.
    medium
  24. 24
    Records (C# 9+)
    Define record Point(int X, int Y).
    hard
  25. 25
    Tuple return
    Return a tuple from a method.
    medium
  26. 26
    params keyword
    Variadic method with params int[].
    medium
  27. 27
    Delegate
    Define and use a delegate type.
    hard
  28. 28
    async / await
    Async method that awaits Task.Delay.
    hard
  29. 29
    LINQ GroupBy
    Group words by their length.
    hard
  30. 30
    Extension method
    Extend string with .Shout().
    hard
  31. 31
    Read & echo a name
    Console.ReadLine then greet.
    intro
  32. 32
    Parse and double
    int.Parse a line, multiply by 2.
    intro
  33. 33
    Circle area
    Use Math.PI to compute πr².
    easy
  34. 34
    Min of three (ternary)
    Use Math.Min twice.
    easy
  35. 35
    Switch expression
    Convert day number to name.
    easy
  36. 36
    Foreach over array
    Sum an int[] with foreach.
    easy
  37. 37
    StringBuilder loop
    Build a string in a loop with StringBuilder.
    medium
  38. 38
    Reverse an array
    In-place reverse via Array.Reverse.
    medium
  39. 39
    FizzBuzz
    Classic 1..15 FizzBuzz with %.
    medium
  40. 40
    IsPrime method
    Static bool IsPrime(int n).
    medium
  41. 41
    List<T> basics
    Add items, then access by index.
    medium
  42. 42
    Dictionary word count
    Count word frequencies.
    medium
  43. 43
    Recursive factorial
    long Factorial(int n) recursive.
    medium
  44. 44
    out parameter
    Method returning two values via out.
    medium
  45. 45
    try / catch parse
    Catch FormatException.
    medium
  46. 46
    Class with auto-properties
    Define Student with Name & Grade.
    medium
  47. 47
    Constructor + ToString
    Override ToString in a class.
    hard
  48. 48
    Inheritance & virtual
    Animal -> Dog with override.
    hard
  49. 49
    Implement IComparable<T>
    Sortable Box by Volume.
    hard
  50. 50
    Generic Swap<T>
    Generic method using ref.
    hard
  51. 51
    LINQ pipeline
    Where + OrderByDescending + Select.
    hard
  52. 52
    Tuple return + deconstruct
    Return (int min, int max).
    hard
  53. 53
    Pattern matching
    is-pattern with property check.
    hard
  54. 54
    Record value equality
    Define a positional record.
    hard
  55. 55
    Null-coalescing & ?.
    Use ?. and ?? together.
    hard
  56. 56
    File.WriteAllText
    Write then read a file.
    hard
  57. 57
    Func<int,int,int>
    Lambda assigned to Func.
    hard
  58. 58
    Vector2: a value type
    Define a readonly struct Vector2 with float X and Y.
    easy
  59. 59
    Vector2: operator overloading
    Overload operator + so two Vector2 values can be added.
    easy
  60. 60
    Clamp player health
    Use Math.Clamp(hp, 0, 100).
    easy
  61. 61
    Distance between two points
    Compute Math.Sqrt(dx*dx + dy*dy).
    easy
  62. 62
    Random spawn point
    Use Random.Shared.Next(0, 100).
    medium
  63. 63
    Direction enum
    Define enum Direction { Up, Down, Left, Right }.
    medium
  64. 64
    Game state switch expression
    Map GameState to a label with a switch expression.
    medium
  65. 65
    Linear interpolation (Lerp)
    Implement static float Lerp(float a, float b, float t).
    medium
  66. 66
    Frame timing with Stopwatch
    Measure elapsed milliseconds with Stopwatch.
    medium
  67. 67
    Player class with TakeDamage
    class Player { int HP } with a TakeDamage(int) method.
    medium
  68. 68
    IWeapon interface
    interface IWeapon { int Damage; void Attack(); }
    medium
  69. 69
    Position as a record struct
    record struct Position(int X, int Y);
    medium
  70. 70
    Detect the host OS
    Use RuntimeInformation.IsOSPlatform.
    medium
  71. 71
    Score event with Action<int>
    Publish an event when score changes.
    hard
  72. 72
    Async asset loader
    async Task<string> LoadAssetAsync(string path).
    hard
  73. 73
    Type pattern matching on entities
    Switch on the runtime type of an Entity.
    hard
  74. 74
    LINQ: closest 3 enemies
    Filter enemies within range, order by distance, take 3.
    hard
  75. 75
    AABB collision check
    Axis-aligned bounding box intersection test.
    hard
  76. 76
    Tiny event bus
    Pub/sub on string channels with Action<object>.
    hard
  77. 77
    Generic object pool
    Pool<T> with Get and Return — avoids GC churn.
    hard
  78. 78
    Capstone: a tiny game loop
    Player + Enemy + Update(deltaTime) + score + game over.
    hard