C#变成关键字
使用into运算符在select子句中设置查询。
以下是我们的员工详细信息列表-
IList<Employee> employee = new List<Employee>() {
new Employee() { EmpID = 1, EmpName = "Tom", EmpMarks = 90, Rank = 8} ,
new Employee() { EmpID = 2, EmpName = "Anne", EmpMarks = 60, Rank = 21 } ,
new Employee() { EmpID = 3, EmpName = "Jack", EmpMarks = 76, Rank = 18 } ,
new Employee() { EmpID = 4, EmpName = "Amy" , EmpMarks = 67, Rank = 20} ,
};现在,使用into运算符获取以k结尾且等级为<20和>5的员工姓名。
var res = from e in employee where e.Rank > 5 where e.Rank < 20 select e into name where name.EmpName.EndsWith("k") select name;让我们看完整的代码。
示例
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
public static void Main() {
IList<Employee> employee = new List<Employee>() {
new Employee() { EmpID = 1, EmpName = "Tom", EmpMarks = 90, Rank = 8} ,
new Employee() { EmpID = 2, EmpName = "Anne", EmpMarks = 60, Rank = 21 } ,
new Employee() { EmpID = 3, EmpName = "Jack", EmpMarks = 76, Rank = 18 } ,
new Employee() { EmpID = 4, EmpName = "Amy" , EmpMarks = 67, Rank = 20} ,
};
// fetching employee name that ends with k and rank is <20 and >5
var res = from e in employee where e.Rank > 5 where e.Rank < 20 select e into name where name.EmpName.EndsWith("k") select name;
foreach (var emp in res) {
Console.WriteLine("Name: "+emp.EmpName);
Console.WriteLine("Marks: "+emp.EmpMarks);
}
}
}
public class Employee {
public int EmpID { get; set; }
public string EmpName { get; set; }
public int EmpMarks { get; set; }
public int Rank { get; set; }
}输出结果
Name: Jack Marks: 76
热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短