默认字符串排序顺序 [英] Default String Sort Order

查看:485
本文介绍了默认字符串排序顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认排序顺序是否是实现细节?还是选择默认比较器?

Is the default sort order an implementation detail? or how is it that the Default Comparer is selected?

这让我想起了建议。 不要在数据库中存储HashCodes。

It reminds me of the advice. "Don't store HashCodes in the database"

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

Is the following Code guaranteed to sort the string in the same order?

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


推荐答案

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

Strings are always sorted in alphabetical order.

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

The default (string.CompareTo()) uses the Unicode comparison rules of the current culture:

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

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

这篇关于默认字符串排序顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆