Compare, in case, not sensitive

This does the same, but the second improved my performance (ok, not mine, but the performance of my application).

foreach (var track in tracks
    .Where(track => track.Name.ToLower() == fileName.ToLower()))

“Upper-casing both strings is silly, because you create two new strings and then still perform a case-sensitive search.”source

foreach (var track in tracks
   .Where(track => string.Equals(track.Name, fileName,
       StringComparison.OrdinalIgnoreCase)))
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s