排序列表/ SortedDictionary怪异的行为 [英] SortedList/SortedDictionary weird behavior
本文介绍了排序列表/ SortedDictionary怪异的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以解释为什么这code:
昏暗的数据作为新的排序列表(StringComparer.InvariantCultureIgnoreCase)
Data.Add(AB,48)
Data.Add(AC,48)
Data.Add(A-D,48)
Data.Add(A-,48)
生成排序列表顺序如下:
A-
AB
AC
广告
预期(逻辑真想)的顺序是:
A-
广告
AB
AC
解决方案
昏暗的数据作为新的排序列表(StringComparer.InvariantCultureIgnoreCase)
我认为这个问题是与指定的排序规则。
修改 InvariantCultureIgnoreCase
到序
或 OrdinalIgnoreCase
解决问题
昏暗的数据作为新的排序列表(StringComparer.OrdinalIgnoreCase)
下面是演示
Can anybody explain why this code:
Dim Data As New SortedList(StringComparer.InvariantCultureIgnoreCase)
Data.Add("AB", 48)
Data.Add("AC", 48)
Data.Add("A-D", 48)
Data.Add("A-", 48)
Generates sorted list with following order:
A-
AB
AC
A-D
Expected (logical and really wanted) order is:
A-
A-D
AB
AC
解决方案
Dim Data As New SortedList(StringComparer.InvariantCultureIgnoreCase)
I think the problem is with the sort rules specified.
Changing InvariantCultureIgnoreCase
to Ordinal
or OrdinalIgnoreCase
solves the problem
Dim Data As New SortedList(StringComparer.OrdinalIgnoreCase)
Here is the Demo
这篇关于排序列表/ SortedDictionary怪异的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文