Equals(String, String, StringComparison) ?

C

csharper

While I was browsing at MSDN, at http://msdn.microsoft.com/en-us/library/bb546166.aspx
, I happen to see some community comments:

<quote>
In the above Linq query. Better performance would be achieved by using
string.Equals() with a StringComparison enumerable as below.

var matchQuery = from word in source
where string.Equals(word, searchTerm,
StringComparison.InvariantCultureIgnoreCase)
select word;

</quote>

Is this real that Equals(String, String, StringComparison) has better
performance than = ?
 
A

Arne Vajhøj

While I was browsing at MSDN, at http://msdn.microsoft.com/en-us/library/bb546166.aspx
, I happen to see some community comments:

<quote>
In the above Linq query. Better performance would be achieved by using
string.Equals() with a StringComparison enumerable as below.

var matchQuery = from word in source
where string.Equals(word, searchTerm,
StringComparison.InvariantCultureIgnoreCase)
select word;

</quote>

Is this real that Equals(String, String, StringComparison) has better
performance than = ?

It is true, because it avoids creating two new String
objects per comparison.

In most cases the overall performance impact
will be insignificant.

But the suggestion fits rather well with Microsofts
recommendations:

http://msdn.microsoft.com/en-us/library/dd465121.aspx#the_details_of_string_comparison

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top