What is the fastest built-in comparison-method for string-types in C#? I don\'t mind about the typographical/semantical meaning: the aim is to use the comparator in sorted lists
I just noticed a 50% performance increase in my own code by comparing string lengths first and if equal then using the string.compare methods. So in a loop I have:
VB:
If strA.length = strB.length then
if string.compare(strA,strB,true) = 0 then
TheyAreEqual
End if
End if
C#:
if(strA.Length == strB.Length)
{
if(string.Compare(strA,strB,true) == 0)
{
//they are equal
}
}
This could be dependant on your own strings but its seems to have worked well for me.