What of this code is faster/more efficient? :
Boolean contains = myString.IndexOf("~", StringComparision.InvariantCultureIgnoreCase)!=-1;
or
Boolean contains = myString.IndexOf('~')!=-1;
I think the second because is a single character, but using the invariant culture ignore case comparer is supposed to be fast too :P
Cheers.
The invariant culture is faster than other cultures, but ordinal comparison is even faster. Making it case insensetive is slower for these settings. So the fastest string comparison setting is StringComparison.Ordinal.
Searching for a character is about twice as fast as the fastest string search.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With