Is there an imperative alternative to the let
keyword in C# LINQ?
E.g. in the MSDN documentation there is the declarative LINQ sample:
var earlyBirdQuery =
from sentence in strings
let words = sentence.Split(' ')
from word in words
let w = word.ToLower()
where w[0] == 'a' || w[0] == 'e'
|| w[0] == 'i' || w[0] == 'o'
|| w[0] == 'u'
select word;
And I would like to write it in an imperative manner. Is it possible?
I know that I can do the following:
var earlyBirdQuery = sentence
.Select(s => s.Split(' '))
.Select(w => w.ToLower())
.Where(w => w[0] == 'a' || w[0] == 'e' || w[0] == 'i' || w[0] == 'o' || w[0] == 'u')
.Select(w => w);
Does it mean that the Select
in the imperative manner has the effect of the from + let
in the declarative manner or are there other ways to mimic the let
and the Select
is not exactly the same as the from + let
?