Re: overloading operator==

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



volkan <slackestdeveloper@xxxxxxxxx> wrote:
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 ?

Casting s1 up to object should be fine. What problems are you having?
An alternative is to use object.ReferenceEquals().

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
.



Relevant Pages

  • overloading operator==
    ... 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). ... how can i check if s1 or s2 is null or not in this overload. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Top 10 software install gripes
    ... single JCLLIB INCLUDE member to tailor an entire installation ... run the exec which is an ISPF dialog that creates files ... for each student, including copying JCL into a CNTL ... edit macro is invoked against each job that copies the ...
    (bit.listserv.ibm-main)
  • Re: We are poor little lambs, who have lost our way, baa baa ... baa ...
    ... Member of Marines not 'sort of person UW wanted to produce' ... Col. Gregory "Pappy" Boyington during World War II (Photo: ... Student senator Jill Edwards, according to minutes of the student ... country - he simply deserves better," Ludeman said. ...
    (rec.models.scale)
  • Sorting on Multiple Columns
    ... sort a data set by multiple columns. ... then sort them by student id, first name, middle initial, and then last ... public int compareTo{ ... compare on the first name ...
    (comp.lang.java.programmer)
  • Re: fft
    ... proposed for the FFT. ... So if you tell students to compare to ... if a student asks how to measure the "numerical ... algorithm, it is a bit deceptive, because that comparison is measuring ...
    (comp.dsp)