nested foreach in LINQ Archives - Anuj Varma, Hands-On Technology Architect, Clean Air Activist https://www.anujvarma.com/tag/nested-foreach-in-linq/ Production Grade Technical Solutions | Data Encryption and Public Cloud Expert Tue, 26 May 2015 18:55:53 +0000 en-US hourly 1 https://wordpress.org/?v=7.0.2 https://www.anujvarma.com/wp-content/uploads/anujtech.png nested foreach in LINQ Archives - Anuj Varma, Hands-On Technology Architect, Clean Air Activist https://www.anujvarma.com/tag/nested-foreach-in-linq/ 32 32 Multiple FROM statements in a LINQ expression https://www.anujvarma.com/multiple-from-statements-in-a-linq-expression/ https://www.anujvarma.com/multiple-from-statements-in-a-linq-expression/#respond Tue, 26 May 2015 18:55:53 +0000 http://www.anujvarma.com/?p=3130 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 { […]

The post Multiple FROM statements in a LINQ expression appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
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);
      }
   }
}

The post Multiple FROM statements in a LINQ expression appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
https://www.anujvarma.com/multiple-from-statements-in-a-linq-expression/feed/ 0