继承List<T>
1、SPList
class SPList<T> : List<T> { public decimal Average(Func<T, decimal> s) { var list = (List<T>)this; decimal price = list.Average(s) * decimal.Parse("0.8"); return price; } }
2、model
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
public class ProductSet { public int ID { get; set; } public string Name { get; set; } public int CategoryID { get; set; } public decimal Price { get; set; } }
3、执行
SPList<ProductSet> products = new SPList<ProductSet>() { new ProductSet{ ID = 10000, Name= "BOOKKX01", Price= 90,CategoryID=0}, new ProductSet{ ID = 10001, Name= "BOOKKX02", Price= 70,CategoryID=0}, new ProductSet{ ID = 10002, Name= "BOOKKX03", Price= 80,CategoryID=0} }; Console.WriteLine(products.Average(p=>p.Price)); // 64 Console.WriteLine(products.AsEnumerable().Average(p => p.Price)); // 80