C# Puzzle 2

Very poorPoorAverageGoodExcellent (No Ratings Yet) 

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


  1. Dave Shaw says:

    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.


1 Trackbacks

Leave a comment