Posted on 2003-12-03
I have created a C# class for use in a program. In this class, I have overloaded the equals operator so that it compares the Name property of the class to declare equality. The problem comes in when I then try to determine if an instance of that class is null. The execution is passed to the overloaded equals function, but since one or both sides is null, then a System.NullReferenceException is thrown. I am currently currently using the following method as a workaround, but I know there has to be a better way to handle this:
public static bool operator==(ConfigSection left, ConfigSection right)
if((left.Name == right.Name) && (left.Type == right.Type))
Can anyone tell me a better way to do this?