How to apply Distinct() in LINQ only by one property of an object?
Hello everyone! I'm a beginner C# developer and I've encountered this problem.
I have a list of objects of class `Product`:
```csharp
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
public string Category { get; set; }
}
```
And there is a list:
```csharp
List products = new List
{
new Product { Id = 1, Name = "Laptop", Price = 50000, Category = "Electronics" },
new Product { Id = 2, Name = "Mouse", Price = 1500, Category = "Electronics" },
new Product { Id = 3, Name = "Laptop", Price = 55000, Category = "Electronics" },
new Product { Id = 4, Name = "Book", Price = 500, Category = "Books" },
new Product { Id = 5, Name = "Mouse", Price = 1200, Categor
No answers yet.
Log in to leave an answer
Blogs
Top 10 TypeScript Frameworks for Web Development in 2025
Architectural Patterns in TypeScript: From Chaos to Clean Code
Working with JSON in PHP: Parsing and Serialization for Beginners
Const vs Readonly in C#: What to Choose and What's the Difference?