Multiple FROM statements in a LINQ expression
Multiple “from” statements are like nested foreach statements. MSDN example:
var scoreQuery = from student in students
from score in student.Scores
where score > 90
select new { Last = student.LastName, score };
This is the equivalent of:
SomeDupCollection<string, decimal> nameScore = new SomeDupCollection<string, float>();
foreach(Student curStudent in students)
{
foreach(Score curScore in curStudent.scores)
{
if (curScore > 90)
{
nameScore.Add(curStudent.LastName, curScore);
}
}
}
Leave a Reply