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

Home Posts Topics Members FAQ

more efficient - not str1.Equals("xyz") or str1 <> "xyz"?

Hello,

Just checking which is more efficient/better/or correct

Do While something
str1 = dr(i).ToString
If Not str1.Equals("xyz") Then
....

or

If str1 <> "xyz" Then
....

or does it make any difference? or any other syntax?

TIA,
Rich
Nov 20 '05 #1
4 1537
Hi Rich,

This kind of instructions are even when they are a million times in a loop
almost never interesting about efficiency, keep in mind that one show or add
of a visible control can cost you billions more time.

When there was a "better" because of efficiency there would have been not
that much posibilities. So look at good programming where reading for others
is very important before you start optimizing in this part of your program.

I do not like to read statements with str1.Equals("xyz"). That does me think
on languages which no sufficient logical operators and where that has to be
done with methods.

However just a thought,

Cor

Just checking which is more efficient/better/or correct

Do While something
str1 = dr(i).ToString
If Not str1.Equals("xyz") Then
...

or

If str1 <> "xyz" Then
...

or does it make any difference? or any other syntax?

TIA,
Rich

Nov 20 '05 #2
* "Rich" <an*******@discussions.microsoft.com> scripsit:
Just checking which is more efficient/better/or correct

Do While something
str1 = dr(i).ToString
If Not str1.Equals("xyz") Then
...

or

If str1 <> "xyz" Then
...

or does it make any difference? or any other syntax?


Call "ILDASM" on the result to see the "difference".

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3
Very interesting.

With str1.Equals I get this with "ILDASM":

IL_0029: callvirt instance bool [mscorlib]
System.String::Equals(string)
If I use st1 <> "xyz" I get this:

IL_002a: call int32 [Microsoft.VisualBasic]
Microsoft.VisualBasic.CompilerServices.StringType: :StrCmp
(string, string, bool)

It appears from "ILDASM" that str1.Equals is more
efficient overall.

Slowly, I will migrate away from my VB6 habits :).

Thanks,
Rich

-----Original Message-----
* "Rich" <an*******@discussions.microsoft.com> scripsit:
Just checking which is more efficient/better/or correct

Do While something
str1 = dr(i).ToString
If Not str1.Equals("xyz") Then
...

or

If str1 <> "xyz" Then
...

or does it make any difference? or any other syntax?


Call "ILDASM" on the result to see the "difference".

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
.

Nov 20 '05 #4
* "Rich" <an*******@discussions.microsoft.com> scripsit:
With str1.Equals I get this with "ILDASM":

IL_0029: callvirt instance bool [mscorlib]
System.String::Equals(string)
If I use st1 <> "xyz" I get this:

IL_002a: call int32 [Microsoft.VisualBasic]
Microsoft.VisualBasic.CompilerServices.StringType: :StrCmp
(string, string, bool)

It appears from "ILDASM" that str1.Equals is more
efficient overall.

Slowly, I will migrate away from my VB6 habits :).


I would still use '<>', even if its some ns slower. I am not sure how
'StrCmp' and 'Equals' are implemented, so it's hard to tell which one is
faster.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #5

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

Similar topics

14
1999
by: juglesh | last post by:
"$string = isset($xyz) ? $xyz : "something else";" Hello, someone gave code like this in another thread. I understand (by inference) what it does, but have not found any documentation on...
6
2180
by: |-|erc | last post by:
Hi, can a .js file read a parameter into it from the HTML file? this is the code to use in peoples HTML files, each member has their own id. <!-- TopCounters Code START --> <script...
2
2312
by: Santa | last post by:
Hello: I am trying to manipulating the data from the pointer (the below program) in the function "test1", Is there any best way of changing the data from that pointer (I am changing by assigning...
3
1904
by: Alan LeHun | last post by:
I want to attach a context menu to multiple textboxes but I don't know how the extract the name of the textbox that is the subject of the event. I can't seem to do anything with "sender as...
7
19396
by: =?Utf-8?B?UmljaA==?= | last post by:
Hello, I need to check if a textbox (of size = 1) contains a specific value (character). I could say something like If txt1.text.equals("X") or txt1.text.equals("Y")... then... Ideally, I...
16
9146
by: network-admin | last post by:
We have Problems with Access query on Oracle 10g Database with ODBC Connection. The Query_1 is such as select * from xtable where ycolumn <"S" Result = ODBC Faild...
20
3502
by: liujiaping | last post by:
I'm confused about the program below: int main(int argc, char* argv) { char str1 = "abc"; char str2 = "abc"; const char str3 = "abc"; const char str4 = "abc"; const char* str5 = "abc";
5
4931
by: .Net Sports | last post by:
I'm having problems trying to get a record out of a resultset when working with a Datalist control. <%# Container.DataItem( "myfield" )%is how I am displaying the field , but when trying to do an...
71
3226
by: Jack | last post by:
I understand that the standard Python distribution is considered the C-Python. Howerver, the current C-Python is really a combination of C and Python implementation. There are about 2000 Python...
0
7134
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
7014
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
7180
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
7229
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
7395
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4609
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: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1429
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 ...
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.