c#:两个list不同元素,值类型,对象类型

基本值类型

    public static List GetListDiff(List listA,List listB)
    {
        List ret = new List();
        if (listA.Count > listB.Count)
            ret = listA.Except(listB).ToList();
        else {
            ret = listB.Except(listA).ToList();
        }
        return ret;
    }

对象类型

public class DiffDevlopments : IEqualityComparer
{
    public bool Equals(Devlopments x, Devlopments y)
    {
        return x.id == y.id;
    }

    public int GetHashCode(Devlopments obj)
    {
        if (obj == null)
        {
            return 0;
        }
        else
        {
            return obj.ToString().GetHashCode();
        }
    }
}
 List listDiff = DataMgr.m_listDevlopments.Except(newDeve, new DiffDevlopments()).ToList();//差集

注意:长的list在前

你可能感兴趣的:(C#,Unity3d技术笔记,c#,list不同元素,except)