Avatar ·

LINQ Distinct() by specific property of an object

Hello colleagues! I'm new to C# and LINQ, and I've encountered this problem. \n\nI have a list of objects of class `Product`:\n\n```csharp\npublic class Product\n{\n public int Id { get; set; }\n public string Name { get; set; }\n public decimal Price { get; set; }\n}\n```\n\nI populate the list with data, and there may be duplicates by the `Name` field. For example:\n\n```csharp\nvar products = new List\n{\n new Product { Id = 1, Name = "Apple", Price = 100 },\n new Product { Id = 2, Name = "Banana", Price = 50 },\n new Product { Id = 3, Name = "Apple", Price = 120 },\n new Product { Id = 4, Name = "Cherry", Price = 200 }\n};\n```\n\nI want to get a list of unique products only by the `Name` property, so that, for example, only "Apple", "Banana", "Cherry" remain (without the difference)