C# 获取不同对象列表的方法

C# 获取不同对象列表的方法,c#,linq,lambda,distinct,distinct-values,C#,Linq,Lambda,Distinct,Distinct Values,我有一个物品清单 public class UserProperties { public int Id { get;set; } public string Name { get;set; } public string ColorCode { get; set; } } List<UserProperties> userList = new List<UserProperties>(); 公共类用户属性 { 公共int Id{get;set

我有一个物品清单

public class UserProperties
{
    public int Id { get;set; }
    public string Name { get;set; }
    public string ColorCode { get; set; }
}

List<UserProperties> userList = new List<UserProperties>();
公共类用户属性
{
公共int Id{get;set;}
公共字符串名称{get;set;}
公共字符串颜色代码{get;set;}
}
List userList=新列表();
我需要从这个列表中选择一个不同的列表。在这里,
Id
字段是唯一的字段。有没有可能采取不同的名单


如果是字符串列表的意思,则使用
distinct
。它会起作用的。但在我的例子中,它是一个对象列表。我们不能直接使用distinct。

“我调查了几个网站,但这个解决方案不适用于我。”-你找到了什么解决方案?为什么它们不适用?……我查看了这个网站。为什么它们不适用?特别是,哪一个似乎是您需要的确切解决方案?“我们不能直接使用distinct。”-如果你为它准备了类,你绝对可以,就像你链接到的问题中所描述的那样。如果问题是要有一个具有唯一ID的列表和索引器,那么在注释中给出的解决方案是实现列表的包装器。