473,386 Members | 1,842 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Advantage to using equals()

Hi

Whats the advantage in using .equals when comparing strings rather
than the = sign?

Thanks

NY

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
Jul 21 '05 #1
5 1328
> Whats the advantage in using .equals when comparing strings rather
than the = sign?


I saw just in another newsgroup that somebody is paid per line that he
writes in his programs and need a general overal project rowcount for that.

It can be an advantage maybe when you are paid per character you type. For
the rest I see nothing, it needs to do a method to do the evaluation which
has surely something as the = sign in it.

Cor
Jul 21 '05 #2
There is no significant difference.
However, using the instance method Equals should save you a couple of
function calls,
and i would claim it is therefore faster, although i have never actually
tried it out.
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"nyousfi" <ny*****@yahoo-dot-com.no-spam.invalid> wrote in message
news:41********@Usenet.com...
Hi

Whats the advantage in using .equals when comparing strings rather
than the = sign?

Thanks

NY

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*

Jul 21 '05 #3
the difference between equals() method and operator == ist that the first
one is virtual while the latter is not:

object o == "Hello";
o.equals(string.concat("He", "llo")); // will return true
o==string.concat("He", "llo") // will return false

So when using equals() it doesn't make any difference which type (object)
the variable is, only the actual type counts (string). If you use operator
== on a string variable and a object variable operator==(object, object) is
called which returns only true if and only if the objects are the same (the
same address).

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk
"nyousfi" <ny*****@yahoo-dot-com.no-spam.invalid> schrieb im Newsbeitrag
news:41********@Usenet.com...
Hi

Whats the advantage in using .equals when comparing strings rather
than the = sign?

Thanks

NY

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*

Jul 21 '05 #4
cody <no****************@gmx.net> wrote:
the difference between equals() method and operator == ist that the first
one is virtual while the latter is not:

object o == "Hello";
o.equals(string.concat("He", "llo")); // will return true
o==string.concat("He", "llo") // will return false

So when using equals() it doesn't make any difference which type (object)
the variable is, only the actual type counts (string). If you use operator
== on a string variable and a object variable operator==(object, object) is
called which returns only true if and only if the objects are the same (the
same address).


Fortunately, the C# compiler will pick up the above and give you a
warning. This at least helps to reduce the occurrence of bugs caused by
this behaviour.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #5
"cody" <no****************@gmx.net>
the difference between equals() method and operator == ist that the first
one is virtual while the latter is not:

object o == "Hello";
o.equals(string.concat("He", "llo")); // will return true
o==string.concat("He", "llo") // will return false

So when using equals() it doesn't make any difference which type (object)
the variable is, only the actual type counts (string). If you use operator
== on a string variable and a object variable operator==(object, object)
is
called which returns only true if and only if the objects are the same
(the
same address).

--

Fortunately, the VB IDE will pick up the above and give you direct a
warning and wont build. In VBNet is needed to use the IS operator to compare
the adresses of Objects to give a good distinct between values. This at
least helps to reduce the occurrence of bugs caused by
this behaviour.

(You can set those warnings by option by the way in VBNet).

:-)

Cor
Jul 21 '05 #6

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

Similar topics

3
by: Fei Li | last post by:
Hi, take string class as an example, who can explain the difference? Thanks
3
by: Frank Wisniewski | last post by:
Is this suppose to work like this: I have a class called foo in which I tried to override equals and return different answers based on what was passed in. public class foo { private string...
18
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the...
5
by: nyousfi | last post by:
Hi Whats the advantage in using .equals when comparing strings rather than the = sign? Thanks NY *-----------------------*
12
by: Elhanan | last post by:
hi.. i wanted to build a Dictionary Classs that will load my own class called letter, i understood that i implement the IEquatable interface's equles method that then the dictionary would use...
1
by: Omiris | last post by:
I'm trying to use the Equals() method that is defined on the List(Of T) class. The docs seem to state that if T implements the IEquatable interface, then it will use the Equals method that is...
0
by: VeeraLakshmi | last post by:
I am doing a project for internet control using Java,PHP and MySql.All sites should go through the proxy server only.We are giving access rights as allow or deny to the sites.If we type the...
10
by: AZRebelCowgirl73 | last post by:
This is what I have so far: My program! import java.util.*; import java.lang.*; import java.io.*; import ch06.lists.*; public class UIandDB {
7
by: =?Utf-8?B?QWxleCBDb2hu?= | last post by:
In C++, there is an easy technique to provide an overloaded Equals() method. A straightforward translation to C# causes a stack overflow. Why does b.Equals(ba) in the snippet below not understand...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...

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.