What does Console.WriteLine(0.1 + 0.2 == 0.3); print in C#?
Correct answer A. False
The literals are doubles, which are stored in binary. Neither 0.1 nor 0.2 has an exact binary representation, so their sum is 0.30000000000000004, which differs from the double nearest 0.3. The comparison is therefore false and Console prints False. To compare doubles safely, check whether the difference is below a small tolerance, or use decimal for exact base-10 values.
Answer checked How we write and check questions
Discussion