linq distinct oder gruppieren nach mehreren Eigenschaften
Wie kann ich mit c # und Linq eineresult
aus der nächsten Liste:
var pr = new List<Product>()
{
new Product() {Title="Boots",Color="Red", Price=1},
new Product() {Title="Boots",Color="Green", Price=1},
new Product() {Title="Boots",Color="Black", Price=2},
new Product() {Title="Sword",Color="Gray", Price=2},
new Product() {Title="Sword",Color="Green",Price=2}
};
Result
:
{Title="Boots",Color="Red", Price=1},
{Title="Boots",Color="Black", Price=2},
{Title="Sword",Color="Gray", Price=2}
Ich weiß, dass ich verwenden sollteGroupBy
oderDistinct
, aber verstehen, wie man bekommt, was benötigt wird
List<Product> result = pr.GroupBy(g => g.Title, g.Price).ToList(); //not working
List<Product> result = pr.Distinct(...);
Bitte helfen Sie