从一开始的继承Icomparer接口到现在的扩展方法和lambda表达式:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace In_Depth_Demo
{
class Program
{
static void Main(string[] args)
{
List<Product> list = new List<Product>()
{
new Product() { name = "a", price = 1 },
new Product() { name = "1", price = 2 },
new Product() { name = "2", price = 3 },
new Product() { name = "1", price = 4 }
};
//扩展方法
foreach (Product obj in list.OrderByDescending(p => p.price)) //倒叙排列
{
Console.WriteLine(obj.price);
}
//lambda
//list.Sort((x, y) => x.price.CompareTo(y.price)); //根