Linq 透明标识符

时间:2022-06-05 14:35:53
            IEnumerable<Person> list = new List<Person>
{
new Person {Age = , Id = },
new Person {Age = , Id = },
new Person {Age = , Id = },
new Person {Age = , Id = },
new Person {Age = , Id = },
new Person {Age = , Id = },
}; var result = from p in list
//透明标识符 let , 避免了计算两次 p.Id 的平方
let length = Math.Pow(p.Id, )
orderby length
select new { p.Age, length }; foreach (var person in result)
{
Console.WriteLine(person.length + ":" + person.Age);
}