我想按数量顺序打印产品。总量较大的产品应该是第一个。
我在这里错过了什么,因为它没有按顺序或总数打印
class Program
{
static void Main()
{
var products=new List<Product>
{
new Product {Name = "Apple", Total = 5},
new Product {Name = "Pear", Total = 10}
};
var productsByGreatestQuantity = products.OrderBy(x => x.Total);
foreach (var product in productsByGreatestQuantity)
{
System.Console.WriteLine(product.Name);
}
System.Console.Read();
}
}
public class Product
{
public string Name { get; set; }
public int Total { get; set; }
}
var data = products.OrderByDescending(x => x.Total);
更改:
var productsByGreatestQuantity = products.OrderBy(x => x.Total);
自:
var productsByGreatestQuantity = products.OrderByDescending(x => x.Total);