我想按数量顺序打印产品,总数量大的先打印。
我在这里遗漏了什么,因为它没有按顺序或全部打印
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);
关于c# - 你如何在linq中按最大数排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6013334/