Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You don't have to guess about run-times or versions, just use this CaseInsensitiveStringComparer class that I made in my spare time (you can pass it to the constructor of the dictionary or if you are using .NET 3.5, a HashSet):</p> <pre><code>/// &lt;summary&gt; /// StringComparer that is basically the same as StringComparer.OrdinalIgnoreCase, except that the hash code function is improved and guaranteed not to change. /// &lt;/summary&gt; public class CaseInsensitiveStringComparer : StringComparer { /// &lt;summary&gt; /// Compares two strings, ignoring case /// &lt;/summary&gt; /// &lt;param name="x"&gt;First string&lt;/param&gt; /// &lt;param name="y"&gt;Second string&lt;/param&gt; /// &lt;returns&gt;Compare result&lt;/returns&gt; public override int Compare(string x, string y) { return StringComparer.OrdinalIgnoreCase.Compare(x, y); } /// &lt;summary&gt; /// Checks if two strings are equal, ignoring case /// &lt;/summary&gt; /// &lt;param name="x"&gt;First string&lt;/param&gt; /// &lt;param name="y"&gt;Second string&lt;/param&gt; /// &lt;returns&gt;True if strings are equal, false if not&lt;/returns&gt; public override bool Equals(string x, string y) { return Compare(x, y) == 0; } /// &lt;summary&gt; /// Gets a hash code for a string, ignoring case /// &lt;/summary&gt; /// &lt;param name="obj"&gt;String to get hash code for&lt;/param&gt; /// &lt;returns&gt;Hash code&lt;/returns&gt; public override int GetHashCode(string obj) { if (obj == null) { return 0; } int hashCode = 5381; char c; for (int i = 0; i &lt; obj.Length; i++) { c = obj[i]; if (char.IsLower(c)) { c = char.ToUpperInvariant(c); } hashCode = ((hashCode &lt;&lt; 5) + hashCode) + c; } return hashCode; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload