P
Pesso
I'm having a difficulty compairing null to a class object whose "equal"
operator is overridden.. Consider the following:
class Foo
{
// ...
public static bool operator==(Foo f1, Foo f2)
{ return (f1.n == f2.n); }
Now the following throws:
Foo foo = new Foo();
if(null == foo) // throws System.NullReferenceException
{ //
If I check for null inside my operator override, it causes stack overflow.
public static bool operator==(Foo f1, Foo f2)
{
if(null == t1) ... // stack overflow
So my question is what's the correct way to handle null comparison when your
class overrides the equal operator?
operator is overridden.. Consider the following:
class Foo
{
// ...
public static bool operator==(Foo f1, Foo f2)
{ return (f1.n == f2.n); }
Now the following throws:
Foo foo = new Foo();
if(null == foo) // throws System.NullReferenceException
{ //
If I check for null inside my operator override, it causes stack overflow.
public static bool operator==(Foo f1, Foo f2)
{
if(null == t1) ... // stack overflow
So my question is what's the correct way to handle null comparison when your
class overrides the equal operator?