You can overload both != and == differently. This is required to implement ternary logic.
Check out the following: public class Test { public static void Main(string[] args) { Test t1 = new Test(); Test t2 = new Test(); System.Console.WriteLine(t1 == t2); System.Console.WriteLine(t1 != t2); } public static bool operator==(Test t1, Test t2) { System.Console.WriteLine("=="); return false; } public static bool operator!=(Test t1, Test t2) { System.Console.WriteLine("!="); return false; } } Regards, Jeroen > -----Original Message----- > From: dotnet discussion [mailto:[EMAIL PROTECTED]] > On Behalf Of Shawn Wildermuth > Sent: Saturday, May 04, 2002 21:12 > To: [EMAIL PROTECTED] > Subject: Re: [DOTNET] What is the correct way to test for Is > Nothing in C#? > > > First of all, you can't overload the != directly, only == (you get != > from the == operation). Second, I would say: > > if (xyz != null) > > Or > > if (!(xys == null)) > > Both are equivalent since you can only overload the == operator (of > course the second one is just plain ugly I wouldn't really > use it except > to show this point). > > Thanks, > > Shawn Wildermuth > [EMAIL PROTECTED] > > > -----Original Message----- > > From: dotnet discussion [mailto:[EMAIL PROTECTED]] > > On Behalf Of David Ferguson > > Sent: Saturday, May 04, 2002 3:06 PM > > To: [EMAIL PROTECTED] > > Subject: [DOTNET] What is the correct way to test for Is > > Nothing in C#? > > > > > > In VB I would say... > > > > if (Not xyz Is Nothing) > > > > In C# I am inclined to say... > > > > if (xyz != null) > > > > but I am concerned that an object might override operator !=. > > What is the recommended way to do this test in C#? > > > > Thanks...David > > > > You can read messages from the DOTNET archive, unsubscribe > > from DOTNET, or subscribe to other DevelopMentor lists at > > http://discuss.develop.com. > > > > You can read messages from the DOTNET archive, unsubscribe > from DOTNET, or > subscribe to other DevelopMentor lists at http://discuss.develop.com. > You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.