Properly Comparing Strings with Globalization and Performance in .NET

A must read about string comparison options and also very important performance notes !

code-performance-book-cover-2-5x-1In Microsoft .NET there are many ways to compare strings. I would say that most of the code I analyze, I see it done one of these two ways:

bool result = email1 == email2;
bool result = email1.Equals(email2);

Is this the best way to compare strings? The quick answer is no. While this works, it doesn’t take into consideration localization and globalization. I’ve seen many developers convert the strings to lower or uppercase characters which does affect performance  and might not have the results they expect. So, let us see how to properly compare strings while thinking about globalization and performance.

Here is how Wikipedia defines localization and globalization:

In computing, internationalization and are means of adapting computer software to different languages, regional peculiarities and technical requirements of a target locale. Internationalization is the process of designing a software application so that it can be adapted to various…

View original post 511 more words

Leave a comment

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

You are commenting using your 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: