tags:

views:

20

answers:

1

Dim rowChinaVisa As DataRow

CodeRush is suggesting that I change this line

If rowChinaVisa("sex").ToString = "M" Then

to:

If String.Compare(rowChinaVisa("sex").ToString, "M", False) = 0 Then

I prefer how the orig line reads, but I am wondering if the recommended line is more efficient. Perhaps for LONG strings only?

+2  A: 

The first is more readable, but String.Compare has better performance, but for such a small string it doesnt really matter.

I tried to find an article I read a while back where the guy compared performance on different string compare and equals methods, if anyone knows what im talking about please link me :p

kyndigs
That was my suspicion. Still, I would be interested in an answer to your question. ty
Velika
Take look at String.CompareOrdinal, this has good performance and is faster than String.Compare.
kyndigs
Also keep in mind that string.compare (and it's related functions) can take into account regional comparison issues, that a simple = compare won't
drventure
The equality operator (=) calls the String.Equals method. You can read about performance of these methods (Equals and Compare) here: http://blogs.msdn.com/b/kirillosenkov/archive/2010/09/22/what-s-faster-string-equals-or-string-compare.aspx
Alex Skorkin