C# defies logic
Posted
Fri, Sep 7 2007 2:33
by
bill
C# has some interesting rules for operators on nullable types. Given:
int? x ;
int? y ;
Laws of transitivity tells us that if x is equal to y, (x == y), then x<= y would be true too. Well not in C#.
With this function:
static void test(int? arg1, int? arg2)
{
Console.WriteLine("arg1 == arg2 returns {0}", (arg1 == arg2));
Console.WriteLine("arg1 <= arg2 returns {0}", (arg1 <= arg2));
}
The output in some cases will be:
arg1 == arg2 returns True
arg1 <= arg2 returns False
Sad to see C# break basic laws of logic and mathematics like this. :(
Thankfully VB doesn't make this mistake :)