Mark Oliver <ma*********@comcast.net> wrote:
When I test my user defined class type passed parameter variable for null
it throws an exception. If I use class "string" the null test doesn't
through an exception. What could I be doing in my class that causes the
exception?
Chances are you've overridden == in some way that assumes that both
arguments are non-null (e.g. calling firstArgument.Equals
(secondArgument)). If you make the first few lines of your operator ==
override:
if ((Object)first==(Object)second)
return true;
if ((Object)first==null || (Object)second==null)
return false;
and then do whatever else you were doing, you should be fine.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too