<p>I have some code like this:</p>

<pre><code>If key.Equals("search", StringComparison.OrdinalIgnoreCase) Then
    DoSomething()
End If
</code></pre>

<p>I don't care about the case. Should I use <code>OrdinalIgnoreCase</code>, <code>InvariantCultureIgnoreCase</code>, or <code>CurrentCultureIgnoreCase</code>?</p>

[{'answer_id': 72718, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 1, 'selected': False, 'text': "<p>It depends on what you want, though I'd shy away from invariantculture unless you're <em>very</em> sure you'll never want to localize the code for other languages.  Use CurrentCulture instead.</p>\n\n<p>Also, OrdinalIgnoreCase should respect numbers, which may or may not be what you want.</p>\n"}, {'answer_id': 72766, 'author': 'Robert Taylor', 'author_id': 6375, 'author_profile': 'https://Stackoverflow.com/users/6375', 'pm_score': 9, 'selected': True, 'text': '<p><strong><a href="https://learn.microsoft.com/en-us/dotnet/standard/base-types/best-practices-strings#choosing-a-stringcomparison-member-for-your-method-call" rel="noreferrer">Newer .Net Docs now has a table to help you decide which is best to use in your situation.</a></strong></p>\n\n<p>From MSDN\'s "<a href="https://learn.microsoft.com/en-us/previous-versions/dotnet/articles/ms973919(v=msdn.10)" rel="noreferrer">New Recommendations for Using Strings in Microsoft .NET 2.0</a>"</p>\n\n<blockquote>\n  <p>Summary: Code owners previously using the <code>InvariantCulture</code> for string comparison, casing, and sorting should strongly consider using a new set of <code>String</code> overloads in Microsoft .NET 2.0. <em>Specifically, data that is designed to be culture-agnostic and linguistically irrelevant</em> should begin specifying overloads using either the <code>StringComparison.Ordinal</code> or <code>StringComparison.OrdinalIgnoreCase</code> members of the new <code>StringComparison</code> enumeration. These enforce a byte-by-byte comparison similar to <code>strcmp</code> that not only avoids bugs from linguistic interpretation of essentially symbolic strings, but provides better performance.</p>\n</blockquote>\n'}, {'answer_id': 72780, 'author': 'Bullines', 'author_id': 27870, 'author_profile': 'https://Stackoverflow.com/users/27870', 'pm_score': 2, 'selected': False, 'text': "<p>I guess it depends on your situation.  Since ordinal comparisons are actually looking at the characters' numeric Unicode values, they won't be the best choice when you're sorting alphabetically. For string comparisons, though, ordinal would be a tad faster.</p>\n"}, {'answer_id': 6406284, 'author': 'Sam Saffron', 'author_id': 17174, 'author_profile': 'https://Stackoverflow.com/users/17174', 'pm_score': 6, 'selected': False, 'text': '<h3>It all depends</h3>\n<p>Comparing unicode strings is hard:</p>\n<blockquote>\n<p>The implementation of Unicode string\nsearches and comparisons in text\nprocessing software must take into\naccount the presence of equivalent\ncode points. In the absence of this\nfeature, users searching for a\nparticular code point sequence would\nbe unable to find other visually\nindistinguishable glyphs that have a\ndifferent, but canonically equivalent,\ncode point representation.</p>\n</blockquote>\n<p>see: <a href="http://en.wikipedia.org/wiki/Unicode_equivalence" rel="noreferrer">http://en.wikipedia.org/wiki/Unicode_equivalence</a></p>\n<hr />\n<p>If you are trying to compare 2 unicode strings in a case insensitive way and want it to work <strong>EVERYWHERE</strong>, you have an impossible problem.</p>\n<p>The classic example is the <a href="http://en.wikipedia.org/wiki/Turkish_dotted_and_dotless_I" rel="noreferrer">Turkish i</a>, which when uppercased becomes İ (notice the dot)</p>\n<p>By default, the .Net framework usually uses the <a href="http://msdn.microsoft.com/en-us/library/system.threading.thread.currentculture.aspx" rel="noreferrer">CurrentCulture</a> for string related functions, with a very important exception of <code>.Equals</code> that uses an ordinal (byte by byte) compare.</p>\n<p>This leads, by design, to the various string functions behaving differently depending on the computer\'s culture.</p>\n<hr />\n<p>Nonetheless, sometimes we want a &quot;general purpose&quot;, case insensitive, comparison.</p>\n<p>For example, you may want your string comparison to behave the same way, no matter what computer your application is installed on.</p>\n<p>To achieve this we have 3 options:</p>\n<ol>\n<li>Set the culture explicitly and perform a case insensitive compare using unicode equivalence rules.</li>\n<li>Set the culture to the Invariant Culture and perform case insensitive compare using unicode equivalence rules.</li>\n<li>Use <a href="http://msdn.microsoft.com/en-us/library/system.stringcomparer.ordinalignorecase.aspx" rel="noreferrer">OrdinalIgnoreCase</a> which will uppercase the string using the InvariantCulture and then perform a byte by byte comparison.</li>\n</ol>\n<p>Unicode equivalence rules are complicated, which means using method 1) or 2) is more expensive than <code>OrdinalIgnoreCase</code>. The fact that <code>OrdinalIgnoreCase</code> does not perform any special unicode normalization, means that some strings that render in the same way on a computer screen, <em>will not</em> be considered identical. For example: <code>&quot;\\u0061\\u030a&quot;</code> and <code>&quot;\\u00e5&quot;</code> both render å. However in a ordinal compare will be considered different.</p>\n<p>Which you choose heavily depends on the application you are building.</p>\n<ul>\n<li>If I was writing a line-of-business app which was only used by Turkish users, I would be sure to use method 1.</li>\n<li>If I just needed a simple &quot;fake&quot; case insensitive compare, for say a column name in a db, which is usually English I would probably use method 3.</li>\n</ul>\n<p>Microsoft has their <a href="http://msdn.microsoft.com/en-us/library/ms973919.aspx" rel="noreferrer">set of recommendations</a> with explicit guidelines. However, it is really important to understand the notion of unicode equivalence prior to approaching these problems.</p>\n<p>Also, please keep in mind that OrdinalIgnoreCase is a <a href="http://www.siao2.com/2004/12/29/344136.aspx" rel="noreferrer">very special kind</a> of beast, that is picking and choosing a bit of an ordinal compare with some mixed in lexicographic aspects. This can be confusing.</p>\n'}, {'answer_id': 11548935, 'author': 'TheMoot', 'author_id': 130112, 'author_profile': 'https://Stackoverflow.com/users/130112', 'pm_score': -1, 'selected': False, 'text': '<p>The very simple answer is, unless you are using Turkish, you don\'t need to use InvariantCulture.</p>\n\n<p>See the following link:</p>\n\n<p><a href="https://stackoverflow.com/questions/3550213/in-c-sharp-what-is-the-difference-between-toupper-and-toupperinvariant">In C# what is the difference between ToUpper() and ToUpperInvariant()?</a> </p>\n'}]
['https://Stackoverflow.com/questions/72696', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/7072/']