我有一个执行各种比较的分拣机。Resharper 说我应该从 更改String.CompareTo
为String.CompareOrdinal
。这真的提供了很多好处还是我应该调整检查规则?
相比于:
config.Sort(delegate(configData data1, configData data2)
{
if (data1.SettingName.Equals(data2.SettingName))
{
string m1 = data1.SettingMachine;
string m2 = data2.SettingMachine;
if (m1 == null)
m1 = string.Empty;
if (m2 == null)
m2 = string.Empty;
return m1.CompareTo(m2);
}
return data1.SettingName.CompareTo(data2.SettingName);
});
比较序数:
config.Sort(delegate(configData data1, configData data2)
{
if (data1.SettingName.Equals(data2.SettingName))
{
string m1 = data1.SettingMachine;
string m2 = data2.SettingMachine;
if (m1 == null)
m1 = string.Empty;
if (m2 == null)
m2 = string.Empty;
return String.CompareOrdinal(m1, m2); ;
}
return String.CompareOrdinal(data1.SettingName, data2.SettingName);
});