var studentQuery5 = from student in students let totalScore = student.Scores[0] + student.Scores[1] + student.Scores[2] + student.Scores[3] where totalScore / 4 < student.Scores[0] select student.Last + " " + student.First; //select totalScore
var studentQuery6 = from student in students let totalScore = student.Scores[0] + student.Scores[1] + student.Scores[2] + student.Scores[3] select totalScore; double averageScore = studentQuery6.Average();
var studentQuery8 = from student in students let x = student.Scores[0] + student.Scores[1] + student.Scores[2] + student.Scores[3] where x > averageScore selectnew { id = student.ID, score = x };
// Join products and categories based on CategoryId var query = from product in products join category in categories on product.CategoryId equals category.Id selectnew { product.Name, category.CategoryName };
比较集运算
Distinct
返回的序列包含输入序列的唯一元素
1 2 3 4 5 6 7 8 9 10
string[] planets = { "Mercury", "Venus", "Venus", "Earth", "Mars", "Earth" }; IEnumerable<string> query = from planet in planets.Distinct() select planet; /* This code produces the following output: * * Mercury * Venus * Earth * Mars */