Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: .NET
Expertise: Intermediate
Oct 30, 2017

Use the Let Keyword to Create Variables in a LINQ Query

There are cases in which you will find the need to have variables inside a LINQ query to hold an evaluation result. The Let keyword helps in this case. See below for an example:

var oldTeens = from kidAge in kidsAges
               let age = kidAge  14
               where age
               select kidAge;

var result = oldTeens.ToList();
Srinath M S
Thanks for your registration, follow us on our social networks to keep up-to-date