How do you order the highest number in linq

I would like to print products in order of quantity. The product with the largest amount should be the first.

What am I missing here, since it does NOT print in order or in 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; }
}
+5
source share
2 answers
var data = products.OrderByDescending(x => x.Total);
+8
source

Edit:

var productsByGreatestQuantity = products.OrderBy(x => x.Total);

at

var productsByGreatestQuantity = products.OrderByDescending(x => x.Total);
+2
source

All Articles