通过本地化排序列表 [英] Sort List by localization
问题描述
我需要排序列表与LT;串>
包含日语假名。
我怎么能做到这一点在C#
I need to sort a List<string>
which contains Japanese alphabet.
How could I do this in C#?
推荐答案
有一个过载列表< T> ;的.sort(IComparer的< T>比较器)
。您可以通过一个特定文化的比较器的排序方法。下面的代码比较了使用日本的文化设置:
There is an overload List<T>.Sort(IComparer<T> comparer)
. You can pass a culture specific comparer to the sort method. The following code compares using the Japanese culture settings:
myList.Sort(StringComparer.Create(new CultureInfo("ja-JP"), true));
在这种情况下,我通过了真正
作为参数来指示该比较,必须以不区分大小写。在 StringComparer
有几个静态的属性和方法来创建一个合适的比较器:
In this case I passed true
as the argument to indicate that the comparison must be case insensitive. The StringComparer
has a couple of static properties and methods to create a suitable comparer:
StringComparer.CurrentCulture;
StringComparer.CurrentCultureIgnoreCase;
StringComparer.Create(CultureInfo culture, bool ignoreCase);
etc.
您可以找到更多信息的 nofollow的>。
You can find more information on this msdn page.
这篇关于通过本地化排序列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!