c# - 默认字符串排序顺序

标签 c# .net

默认排序顺序是实现细节吗?或者如何选择默认比较器?

这让我想起了建议。 “不要将哈希码存储在数据库中”

以下代码是否保证按相同顺序对字符串进行排序?

string[] randomStrings = { "Hello", "There", "World", "The", "Secrete", "To", "Life", };
randomStrings.ToList().Sort();

最佳答案

字符串始终按字母顺序排序。

默认(string.CompareTo())使用当前区域性的 Unicode 比较规则:

    public int CompareTo(String strB) {
        if (strB==null) { 
            return 1;
        } 

        return CultureInfo.CurrentCulture.CompareInfo.Compare(this, strB, 0);
    } 

关于c# - 默认字符串排序顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14525325/

相关文章:

c# - 域用户的自动完成

c# - 使用 C# 编辑源 css

c# - 我可以防止无效的小型转储文件名吗

c# - 使用 jquery 超时 Ajax 请求?

c# - 在 C# 中,我应该使用 struct 来包装一个对象以实现额外的接口(interface)吗?

c# - 跨平台日志记录

c# - Entity Framework - 唯一索引上的 UPSERT

c# - "Specified cast is not valid"当空值返回为 Nullable<int>

c# - 在哪里可以找到 ASP.NET MVC 插件模式的介绍?

c# - 是否可以使用MySql赋值运算符(:=) in a MySqlCommand?