默认排序顺序是实现细节吗?或者如何选择默认比较器?
这让我想起了忠告。“不要在数据库中存储哈希码”
以下代码是否保证按相同顺序对字符串进行排序?
string[] randomStrings = { "Hello", "There", "World", "The", "Secrete", "To", "Life", };
randomStrings.ToList().Sort();
Run Code Online (Sandbox Code Playgroud)
字符串总是按字母顺序排序。
默认 ( string.CompareTo()) 使用当前区域性的 Unicode 比较规则:
public int CompareTo(String strB) {
if (strB==null) {
return 1;
}
return CultureInfo.CurrentCulture.CompareInfo.Compare(this, strB, 0);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3213 次 |
| 最近记录: |