Distinct in linq?

前端 未结 5 1306
我寻月下人不归
我寻月下人不归 2020-12-31 20:07

I am wondering how can I achieve this?

I want to get only distinct names from a collection of objects

MyObject a = new Object();
a.Name = \'One\';
a.         


        
5条回答
  •  北荒
    北荒 (楼主)
    2020-12-31 20:34

    Personally I suggest you override operator == and != and determine how and why an object is unique there. Then use the Distinct() call on the collection.

    You do have to be careful with null values, see Microsoft's Guidelines for Overloading Equals() and Operator == (C# Programming Guide).

提交回复
热议问题