I have a class Customer that holds an array of class Order.
class Customer
{
public string firstname { get; set; }
public string lastname { get; set; }
public Order[] orders {get; set;}
}
This is my order class:
class Order
{
public string product { get; set; }
public float price{get; set;}
public int quantity { get; set; }
}
I am trying to find the three least expensive products.
I have tried many things but none seem to work. This is what I have at the moment:
var result = customer.SelectMany(x => x.orders);
var Least = result.Distinct().OrderBy(x => x.price).Take(3);
I realized I need to have distinct as I have many orders with the same product name therefore instead of returning the least three expensive products it was just repeating the least expensive product 3 times.