473,499 Members | 1,568 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

relational operator parameters

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
2 1198
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
20987
by: Stub | last post by:
When I try to overload the == operator, it gives me an "error C2804: binary 'operator ==' has too many parameters." bool operator==(const Store& Store1, const Store& Store2); After Adding...
2
1790
by: Bo Sun | last post by:
hi: in the following code: class plus{ int data_item; public:
1
3073
by: Pesko S | last post by:
Hi, Could anybody just point me in a direction where I can find information on how the heck I can update a database with relational data from an XML file. I use stored procedures to insert...
1
2169
by: Tim Fierro | last post by:
Hello, I have had many years using flat file databases (File Express from way back) but am now at a company where a relational database is needed and would carry us into the future. Since I...
1
1243
by: Locia | last post by:
I would like compare all type. I try with this function but I get System.NullReference.Exception if pass in Compare function two int type. Why relational operation isn't defined for basic type...
2
1676
by: Constantine | last post by:
Hi, I have developed one class called CProductInfo providing == and != operator features. I have one problem. When I use this class in my program, say CProductInfo product = null; and...
11
1449
by: Janus | last post by:
Hi, This is a very basic question. What will happen if there is a statement with a relational operator outside while, for, or if conditions? Something like this... ..
14
2537
by: AliceB.Toklas | last post by:
In my Absolute Beginner's Guide to C book by Greg Perry where it is instruction how relational operators work it gives the following example: int i = 5; so the following statement is true: ...
13
1582
by: sulyokpeti | last post by:
I have made a simple python module to handle SQL databases: https://fedorahosted.org/pySQLFace/wiki Its goal to separate relational database stuff (SQL) from algorythmic code (python). A SQLFace...
0
7132
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7009
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7223
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5475
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4602
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3103
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.