LINQ's Distinct() on a particular property

后端 未结 20 2025
一向
一向 2020-11-21 05:05

I am playing with LINQ to learn about it, but I can\'t figure out how to use Distinct when I do not have a simple list (a simple list of integers is pretty easy

20条回答
  •  灰色年华
    2020-11-21 06:01

    In case you need a Distinct method on multiple properties, you can check out my PowerfulExtensions library. Currently it's in a very young stage, but already you can use methods like Distinct, Union, Intersect, Except on any number of properties;

    This is how you use it:

    using PowerfulExtensions.Linq;
    ...
    var distinct = myArray.Distinct(x => x.A, x => x.B);
    

提交回复
热议问题