LINQ笔记-let、into案例

let:在linq中定义变量,可以重复使用

var lowercaseStudentNames = from s in studentList
let lowercaseStudentName = s.StudentName.ToLower()
where lowercaseStudentName.StartsWith("r")
select lowercaseStudentName;
//取出单词首字母 a d g j m p s v y
List<string> strList = new List<string> { "abc def ghi", "jkl mno pqr", "stu vwx yz" }; var firstLetters = from line in strList let words = line.Split(' ') from word in words select word.Substring(0, 1);

into:创建一个临时标识符,该标识符可以存储group、join、select子句结果

var teenAgerStudents = from s in studentList
where s.age > 12 && s.age < 20
select s
into teenStudents
where teenStudents.StudentName.StartsWith("B")
select teenStudents;
var l = from p in personList
                    group p by p.CompanyID into g
                    where g.Count()==2
                    select new { Key = g.Key,Count=g.Count(),Values=g.ToList()};
原文地址:https://www.cnblogs.com/fanfan-90/p/12112392.html