List<string> key  = new List<string>{"02","10","03"};
List<string> num  = new List<string>{"03","02","10"};如何比较 key 与 num 相同呢?

解决方案 »

  1.   

    if (key.OrderBy(x => x).SequenceEqual(num.OrderBy(x => x)))
        ...
      

  2.   

    List<string> key = new List<string> { "02", "10", "03" };
                List<string> num = new List<string> { "03", "02", "10" };
                IEnumerable<string> list = key.Except(num);
                if (list.Count() == 0) MessgeBox.Show("相等"); 
      

  3.   

    这代码是错的List<string> key = new List<string> { "02", "10", "03" };
    List<string> num = new List<string> { "03", "02", "10", "99" };
    IEnumerable<string> list = key.Except(num);
    if (list.Count() == 0) MessgeBox.Show("相等"); 还相等?郁闷的就是回答过的问题反复问,而且还有人给出错误的答案。
      

  4.   

    不好意思,忘记了要Key.coumt>=Num.Count
      

  5.   


    你要考虑 key全包含num,num全包含key,集合中有重复元素等情况。你给出的“修正”还是错的。
      

  6.   


    哦,谢谢Caozhy老师,我的应用里,num、key都不会有重复元素
      

  7.   

    if( key.Count ==num.Count)
    for
    if (key.Contains(num[i])
    true
    else
    false