All Posts in 2021.12


Linq和Lambda 性能对比

Linq和Lambda 性能对比 1.Where() 使用LINQ创建一个简单的where查询 var query = from person in PersonCollection where person.Age.TotalDays > 1000 select person; var result = query.ToList() // This runs the query 使用LAMBDA创建一个相同的查询 var result = PersonCollection.Where(p => p.Age.TotalDays > 1000).ToList(); 查看性能对比查看性能对比 可以看到两者的性能差距并不是很大 2.Any() 如果集合中只要有一项符合条件,将返回一个bool值 同样使用上面的LINQ, …