C# Puzzle 2

Just another little puzzle based on an issue I had at work…

Consider this piece of code :

Console.WriteLine($"x > y is {x > y}");
Console.WriteLine($"!(x <= y) is {!(x <= y)}");

How would you declare and initialize x and y for the program to produce the following, apparently illogical, output?

x > y is False
!(x <= y) is True

3 thoughts on “C# Puzzle 2”

  1. I usually don’t get these… 🙂

    int? x = 0;
    int? y = null;

    null is not greater than any number, positive or negative.

    It is also not less than (or equal to) another number.


Leave a Reply

Your email address will not be published. Required fields are marked *