Marcin Grz?bski <(E-Mail Removed)> wrote:
> I think that a "key" is operator overloading.
> Like a Jon post it before.
>
> MyClass myVar;
>
> if( null==myVar ) {
> }
> Doesn't have a chance to fire MyClass "==" operator function.
Yes it does. Compile and run the following, ignoring the warnings:
using System;
using System.Data;
class Test
{
static void Main()
{
Test t = new Test();
Console.WriteLine (t==null);
Console.WriteLine (null==t);
}
public static bool operator == (Test t1, Test t2)
{
Console.WriteLine ("Operator== called");
Console.WriteLine ("t1={0}", t1);
Console.WriteLine ("t2={0}", t2);
return true;
}
public static bool operator!= (Test t1, Test t2)
{
return false;
}
}
The output is:
Operator== called
t1=Test
t2=
True
Operator== called
t1=
t2=Test
True
In other words, the overloaded operator is called both times.
--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too