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

Home Posts Topics Members FAQ

Equals and "==" operator

Hi,
What is the difference between Object.Equals and "==" operator ?
When we use CollectionBase.List.Remove(object), which methods is used to
compare objects ?

Thanks
Jul 19 '05 #1
3 10034
For interest, there are also performance differences between instance and
static(shared) methods for Equals and the == operator when comparing
strings.

" #Hai" <Re******************@Softhome.net> wrote in message
news:ek**************@TK2MSFTNGP11.phx.gbl...
Hi,
What is the difference between Object.Equals and "==" operator ?
When we use CollectionBase.List.Remove(object), which methods is used to
compare objects ?

Thanks

Jul 19 '05 #2
Hi Anthony!

Can you tell me more about the performance differences. Which way is
fastest?

TIA,

Markus

"Anthony Bouch" <to**@nospamforever.com> schrieb im Newsbeitrag
news:e2**************@TK2MSFTNGP10.phx.gbl...
For interest, there are also performance differences between instance and
static(shared) methods for Equals and the == operator when comparing
strings.

" #Hai" <Re******************@Softhome.net> wrote in message
news:ek**************@TK2MSFTNGP11.phx.gbl...
Hi,
What is the difference between Object.Equals and "==" operator ?
When we use CollectionBase.List.Remove(object), which methods is used to
compare objects ?

Thanks


Jul 19 '05 #3
100
Furthermore, not all languages support operator overloading. So, if one
wants to write language independent code she/he should not rely on operator
overloading. For c# convenince the operators might be overloaded and the
virtual method might be used internally.

B/rgds
100

"Jon Skeet" <sk***@pobox.com> wrote in message
news:MP************************@news.microsoft.com ...
[What does this have to do with Windows forms, by the way? Please limit
your post to relevant groups - preferrably only one!]

#Hai <Re******************@Softhome.net> wrote:
What is the difference between Object.Equals and "==" operator ?


Operators are not applied polymorphically, methods are. For instance:

string x = "hello";
string y = new string (x.ToCharArray());

object a=x;
object b=y;

x==y; // True, because String== is applied
a==b; // False, because Object== is applied, which asserts reference
// identity

x.Equals(y); // True, because String.Equals override Object.Equals
a.Equals(b); // True, because methods are invoked polymorphically
When we use CollectionBase.List.Remove(object), which methods is used to
compare objects ?


Almost certainly Equals - it's the only way that makes sense, really,
given that CollectionBase only knows about Objects, so to remove
entries you'd have to have the exact reference if it used ==.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too

Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2869
by: Arno Huetter | last post by:
Hi there, I try to execute a DB-Update using ADO.NET CommandBuilder (MSORA Data Provider) on Oracle 8.1.6 (unfortunately, ODP.NET seems to require Oracle 9i or above). One of ADO.NET's...
10
10694
by: ambar.shome | last post by:
Dear All, Whats the difference between a copy constructor and assignment operator. We can assign the values of member variables of one object to another object of same type using both of them....
4
3191
by: Chris | last post by:
This is something that has been bugging me for some time. When exactly should I be using == instead of .Equals() ? I see a lot of code that performs object evaluation e.g. Is Object1 the same as...
3
1428
by: Roger | last post by:
What did MS not take the chance to change the silly == operator when they designed C#, to something reasonable like = ? Why change the universal meaning of = ? Wouldn't it be better to have:...
0
1163
by: Klaus Löffelmann | last post by:
Hi, maybe it's already too late, but what is the deal with overwriting Object.Equals. I have to use "overrides overloads" to really overwrite the correct 'version' of equals, even if a single...
4
1536
by: Rich | last post by:
Hello, Just checking which is more efficient/better/or correct Do While something str1 = dr(i).ToString If Not str1.Equals("xyz") Then .... or
1
1335
by: Rob | last post by:
The code below is almost there (it does change the value for EVERY ORDER).... I simply want to be able to change the value of the Delivered Tag to Yes. BUT ONLY if the Order is equal to 123456 ? ...
2
2161
by: Phil Davidson | last post by:
/* (Posted to microsoft.public.dotnet.languages.vc) In C++/CLI under Visual Studio 2005, creating an "enum class" member called "Equals" can cause compiler error C1060 (out of memory) and C1063...
26
1754
by: screechyboy | last post by:
OKay so im new to Javascript Cookies.... I am able to set and return cookie values but i know want to create an if statement! One of my cookies is called "color" and i wish to write a script...
29
2391
by: Java script Dude | last post by:
Greetings, Now I can understand that 0 equal false, but should "" also equal false? Apparently the answer is yes. When I test both Firefox and IE, they both say ""==false . I assume this goes...
0
7131
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
7007
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
7174
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7220
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...
1
6894
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5470
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
3091
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
297
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.