日期:2014-05-18  浏览次数:20710 次

这段啥意思?详细解答一下
/// <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);
  }
  }));
  }

------解决方案--------------------
对Items进行自定义排序,规则就是后面的代码
如果 x1.Key == x2.Key 则根据Value比较,否则就比较Key
------解决方案--------------------
Items.Sort内部进行遍历,Items.Sort已经帮你做了排序算法,你只需要告诉Sort如何比较两个元素就行,

探讨

要是排序,怎么没有遍历啊?

------解决方案--------------------
探讨

要是排序,怎么没有遍历啊?

------解决方案--------------------
key相等就比较Value

否则比较KEY