backendgym backendgym · reps Sign in with GitHubSign in

06Eight comparisons

csharp-reading / reps/06/README.md

Read Program.cs first, then run it: dotnet run --project reps/06. It prints:

1: True
2: True
3: True
4: False
5: False
6: True
7: False
8: True

Lines 2, 3, 5 and 7 are the ones worth explaining.

After the rep
  1. 1 Line 2: what did the compiler do to your program before it ran?
  2. 2 Lines 5 and 7: which == did the compiler pick, and why did the declared type decide it rather than the value's type?
  3. 3 If your rule is "reference types compare by reference", line 3 looks impossible. What's the better rule?
  4. 4 You see if (a == b) where both are declared object. What do you need to know before you can say whether that line is correct?