nullの比較

直感とは異なっていたのでメモ。

using System;

static class Program {
    public static void Main () {
        int? x = null;
        int? y = null;

        if (x == y)
            Console.WriteLine ("yes");
        else 
            Console.WriteLine ("no");

        if (x >= y)
            Console.WriteLine ("yes");
        else
            Console.WriteLine ("no");

        if (x == y || x > y) 
            Console.WriteLine ("yes");
        else
            Console.WriteLine ("no");
    }
}

/* result
 yes
 no
 yes
 */

>=は( > or == )では無い。