In a query expression, it is sometimes useful to store the result of a
sub-expression in order to use it in subsequent clauses. You can do this
with the let
keyword, which creates a new range variable and initializes it with the result of the expression you supply.
var names = new string[] { "Dog", "Cat", "Giraffe", "Monkey", "Tortoise" };
var result =
from animalName in names
let nameLength = animalName.Length
where nameLength > 3
orderby nameLength
select animalName;
Reference: Kill Your Tech Interview
No comments:
Post a Comment