Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I came across this SO post, while I was trying to figure out why I was having problems retrieving (string) keys that were inserted into a SortedList, after I discovered the cause was the odd behaviour of the .Net 40 and above comparers (a1 &lt; a2 and a2 &lt; a3, but a1 > a3). </p> <p>My struggle to figure out what was going on can be found here: <a href="https://stackoverflow.com/questions/17599084/c-sharp-sortedliststring-tvalue-containskey-for-successfully-added-key-return">c# SortedList&lt;string, TValue&gt;.ContainsKey for successfully added key returns false</a>.</p> <p>You may want to have a look at the "UPDATE 3" section of my SO question. It appears that the issue was reported to Microsoft in Dec 2012, and closed before the end of january 2013 as "won't be fixed". Additionally it lists a workaround that may be used.</p> <p>I created an implementation of this recommended workaround, and verified that it fixed the problem that I had encountered. I also just verified that this resolves the issue you reported.</p> <pre><code>public static void SO_13254153_Question() { string x = "\u002D\u30A2"; // or just "-ア" if charset allows string y = "\u3042"; // or just "あ" if charset allows var invariantComparer = new WorkAroundStringComparer(); var japaneseComparer = new WorkAroundStringComparer(new System.Globalization.CultureInfo("ja-JP", false)); Console.WriteLine(x.CompareTo(y)); // positive one Console.WriteLine(y.CompareTo(x)); // positive one Console.WriteLine(invariantComparer.Compare(x, y)); // negative one Console.WriteLine(invariantComparer.Compare(y, x)); // positive one Console.WriteLine(japaneseComparer.Compare(x, y)); // negative one Console.WriteLine(japaneseComparer.Compare(y, x)); // positive one } </code></pre> <p>The remaining problem is that this workaround is so slow it is hardly practical for use with large collections of strings. So I hope Microsoft will reconsider closing this issue or that someone knows of a better workaround.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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