bool sequenceEqual = oldList.SequenceEqual(newList);

解决方案 »

  1.   

    假设二个list值都是一样的,怎么应怎么做?高人给个示例啊
      

  2.   

    取两者差集,看差集是否为0个 List<String> oldList = new List<String>();
                List<String> newList = new List<String>();
                oldList.Add("diaoer1");
                oldList.Add("diaoer2");
                oldList.Add("diaoer3");
                oldList.Add("diaoer4");            newList.Add("diaoer1");
                newList.Add("diaoer2");
                newList.Add("diaoer3");
                newList.Add("diaoer4");           if( oldList.Except(newList).Count()==0)
                   //相等
                else 
                //不相等
      

  3.   

    这个方法不可以取吧,如果里边有不同的,则要返回false的,
    oldList.Add("diaoer1");
                oldList.Add("diaoer2");
                oldList.Add("diaoer5");
                oldList.Add("diaoer4");
     
                newList.Add("diaoer1");
                newList.Add("diaoer2");
                newList.Add("diaoer3");
                newList.Add("diaoer4");
    比如上边,则要返回false
      

  4.   

    楼主 你想比较 的是 两个 list里面的值相等 还是 count相等, 还是列相等啊
      

  5.   

     oldList.Add("diaoer2");
                oldList.Add("diaoer5");
                oldList.Add("diaoer4");
     
                newList.Add("diaoer1");
                newList.Add("diaoer2");
                newList.Add("diaoer3");
                newList.Add("diaoer4");值是否相等,不好意思,没表达清楚
      

  6.   

     private static bool ListEqual(List<string> x, List<string> y)
            {
                if (x == null && y == null)
                    return true;
                if (x == null || y == null)
                    return false;
                if (x.Count() != y.Count())
                    return false;            var count= x.Where((a, i) => a != y[i]).Count();
                return count == 0;
            }调用:
    if( ListEqual(oldList, newList))
      //相等
    else
     //不等
      

  7.   

    if( oldList.Except(newList).Count()==0)
    //相等
    else 
    //不相等
    ----------------------------------------
      

  8.   

     List<string> LAppPerson = new List<string>();
     LAppPerson.Add("in");
     LAppPerson.Add("bs");
     LAppPerson.Add("es");
     LAppPerson.Add("in");LAppPerson=LAppPerson.Distinct().ToList();//删除重复项为什么还是in bs es in,没有删除一个in
      

  9.   

    private bool ListEqual(List<long> a, List<long> b)
            {
                List<long> x = new List<long>(a);
                List<long> y = new List<long>(b);
                if (x == null && y == null)
                    return true;
                if (x == null || y == null)
                    return false;
                if (x.Count != y.Count)
                    return false;
                for (int i = 0; i < y.Count; i++)
                {
                    x.Remove(y[i]);
                }
                if (x.Count == 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }