Marco

Marco

  • NA
  • 59
  • 0

overloadingg operator

Oct 27 2007 2:05 PM
Hello, I have this problem:

class Person {
    string name;
    string surname;
    public static bool operator ==(Person p1, Person p2)
    {
            if (p1.name == p2.name && p1.surname == p2.surname) return true;else return false;
     }
}

//main program..
   Person p = p.Mysearch("Tim"); // if it don't found Tim, Mysearch() return null
   if (p == null) { ......} //problem is here

The problem is when I check for p ==null; I have defined == the check p.name and p.surname but null HASN'T any attribute (it isn't a person...

How can I solve it problem??
thanks.
  

Answers (3)