How to get a distinct list from a List of objects?

后端 未结 10 1254
滥情空心
滥情空心 2020-12-24 04:59

I have a List someList.

class MyClass
{
    public int Prop1...
    public int Prop2...
    public int Prop3...
}
10条回答
  •  猫巷女王i
    2020-12-24 05:16

    Simple way to remove duplications where all properties are equal:

    System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer();
    serviceList = serviceList.GroupBy(s => jss.Serialize(s)).Select(group => group.First()).ToList();
    

提交回复
热议问题