3
Answers

overloadingg operator

Marco

Marco

17y
2.1k
1
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)