|
-
February 18th, 2009, 05:54 PM
#3
Re: testing if an object is null
Then your overloaded operator should do a nullcheck before it does the usual equality check.
Alternatively if you cast to 'object' first, you'll use the regular (non-overloaded) comparison:
Code:
if ((object)myObject == null) {
Console.WriteLine ("I'm using the regular '==' and i'm null");
}
EDIT: Generally speaking you should only override == for immutable types. So if your type is mutable, then don't override '=='. If you want value comparison, you should be overriding the 'Equals' method.
www.monotorrent.com For all your .NET bittorrent needs
NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|