linq中如何按最大数字排序
我想按数量顺序打印产品。总量较大的产品应该排在第一位。
我在这里缺少什么,因为它没有按顺序或总计打印
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; }
}
I would like to print products in order of quantity.The product with a bigger total should be first.
What am I missing here as it's NOT printing in order or total
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; }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更改:
至:
Change:
to: