By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,951 Members | 1,591 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,951 IT Pros & Developers. It's quick & easy.

relational operator parameters

P: n/a
I'm confused with creating the == operator for my class. It appears that c#
requires the signature:
public static bool operator==(Type a, Type b);

I want to use:
public bool operator==(Type RightHandSide)
{
return this.SomeMember = RightHandSide.SomeMember;
}
This can't be correct, that I can't make a member operator to my class and
use the 'this' reference?
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
This can't be correct, that I can't make a member operator to my class and
use the 'this' reference?


The operator should work even if the left hand side operand is null.

Type a = null, b = null;
if (a == b) ...

If it was an instance operator this would throw a
NullReferenceException.
Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 17 '05 #2

P: n/a

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:ek**************@TK2MSFTNGP12.phx.gbl...
This can't be correct, that I can't make a member operator to my class anduse the 'this' reference?


The operator should work even if the left hand side operand is null.

Type a = null, b = null;
if (a == b) ...

If it was an instance operator this would throw a
NullReferenceException.

Ah. I see. I have since added the Equals() method
thanks for the heads up!
Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.