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
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; } }
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
//不相等
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
oldList.Add("diaoer5");
oldList.Add("diaoer4");
newList.Add("diaoer1");
newList.Add("diaoer2");
newList.Add("diaoer3");
newList.Add("diaoer4");值是否相等,不好意思,没表达清楚
{
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
//不等
//相等
else
//不相等
----------------------------------------
LAppPerson.Add("in");
LAppPerson.Add("bs");
LAppPerson.Add("es");
LAppPerson.Add("in");LAppPerson=LAppPerson.Distinct().ToList();//删除重复项为什么还是in bs es in,没有删除一个in
{
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;
}
}