/// <summary>
/// 排序
/// </summary>
public void Sort()
{
this.Items.Sort(new Comparison<KeyValuePair<string, string>>((x1, x2) =>
{
if (x1.Key == x2.Key)
{
return string.Compare(x1.Value, x2.Value);
}
else
{
return string.Compare(x1.Key, x2.Key);
}
}));
}
/// 排序
/// </summary>
public void Sort()
{
this.Items.Sort(new Comparison<KeyValuePair<string, string>>((x1, x2) =>
{
if (x1.Key == x2.Key)
{
return string.Compare(x1.Value, x2.Value);
}
else
{
return string.Compare(x1.Key, x2.Key);
}
}));
}
如果 x1.Key == x2.Key 则根据Value比较,否则就比较Key
你的代码就是List(Of T).Sort排序方法本身就是个排序方法后面是自定义了一个System.Comparison(Of T)排序规则对List(Of T)中的元素进行排序