7. 关键字

let关键字

  • 不使用let关键字
IList<Student> studentList = new List<Student>() {
    new Student() { StudentID = 1, StudentName = "John", Age = 18 } ,
    new Student() { StudentID = 2, StudentName = "Steve",  Age = 21 } ,
    new Student() { StudentID = 3, StudentName = "Bill",  Age = 18 } ,
    new Student() { StudentID = 4, StudentName = "Ram" , Age = 20 } ,
    new Student() { StudentID = 5, StudentName = "Ron" , Age = 21 }
};
//需要做2次的小写转化
var lowercaseStudentNames = from s in studentList
                            where s.StudentName.ToLower().StartsWith("r")
                            select s.StudentName.ToLower();
  • 使用let关键字
var lowercaseStudentNames = from s in studentList
                            let lowercaseStudentName = s.StudentName.ToLower()
                                where lowercaseStudentName.StartsWith("r")
                                select lowercaseStudentName;

foreach (var name in lowercaseStudentNames)
    Console.WriteLine(name);

into关键字

var teenAgerStudents = from s in studentList
    where s.age > 12 && s.age < 20
    select s
        into teenStudents
        where teenStudents.StudentName.StartsWith("B")
        select teenStudents;
上一篇:springboot管理及监控之actuator


下一篇:django---orm---总结---“一对一”---“一对多”---“多对多”---“增删改查”