This question already has answers here:
Get distinct items from a list
                                
                                    (4个答案)
                                
                        
                        
                            Linq Distinct() by name for populate a dropdown list with name and value
                                
                                    (7个答案)
                                
                        
                        
                            LINQ: Distinct values
                                
                                    (7个答案)
                                
                        
                                6年前关闭。
            
                    
我有一个具有以下属性的CarData对象:
PrimaryKey Make Model Year Drivetrain Country

我在List中有大约1000个这些CarData对象:
List<CarData> CarObjects

是否有一种简单的方法来获取不同的Make列表?

最佳答案

var makes = CarObjects.Select(car => car.Make).Distinct();


这会将列表从CarData列表转换为Make列表,然后只查找新列表的不同值。

10-08 09:08
查看更多