Hi,
I have a student class. In this class i overloaded ==,!= and equals so that
they will compare the studentids ( which is a member of the class ).
However i have a problem with null check.
public static bool operator !=(Student s1, Student s2)
{
...
how can i check if s1 or s2 is null or not in this overload.
if i do s1==null it goes recursive
if i typecast s1 down to object class, it seems not working
any ideas ?
Jon Skeet [C# MVP] - 16 Mar 2008 20:06 GMT
> I have a student class. In this class i overloaded ==,!= and equals so that
> they will compare the studentids ( which is a member of the class ).
[quoted text clipped - 6 lines]
> if i typecast s1 down to object class, it seems not working
> any ideas ?
Casting s1 up to object should be fine. What problems are you having?
An alternative is to use object.ReferenceEquals().

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
BlackWasp - 16 Mar 2008 21:01 GMT
Have a look here.
http://www.blackwasp.co.uk/CSharpRelationalOverload.aspx

Signature
BlackWasp
www.blackwasp.co.uk
> Hi,
> I have a student class. In this class i overloaded ==,!= and equals so
[quoted text clipped - 7 lines]
> if i typecast s1 down to object class, it seems not working
> any ideas ?
BlackWasp - 16 Mar 2008 21:06 GMT
D'oh, copy and paste failure!
http://msdn2.microsoft.com/en-us/library/ms173147(VS.80).aspx

Signature
BlackWasp
www.blackwasp.co.uk
> Have a look here.
>
[quoted text clipped - 11 lines]
>> if i typecast s1 down to object class, it seems not working
>> any ideas ?
volkan - 16 Mar 2008 21:58 GMT
thanx solved
> Hi,
> I have a student class. In this class i overloaded ==,!= and equals so
[quoted text clipped - 7 lines]
> if i typecast s1 down to object class, it seems not working
> any ideas ?