TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
p3ya8my02
NA
3
0
Overloading ==, checking for null
Jun 14 2004 2:17 PM
Suppose that I have a Foo class for which I've overloaded the == operator: // Class foo. public static bool operator == (Foo foo1, Foo foo2) { return (foo1.data == foo2.data); } Now I do this: Foo foo = something(); if ( foo == null ) ... Oops: NullReferenceException, because the overloaded == operator was used, and it tried to dereference the "null" that I passed in. So how do I test for a null value if the == operator is overloaded? Sure, I could try to use it and then catch the NullReferenceException, but is there a more elegant solution?
Reply
Answers (
1
)
WSACancelBlockingCall
Localizing applications