In a query expression, the result of storing a subexpression is sometimes helpful and can be used in subsequent clauses. You can let do this by using the keyword, which creates a new scope variable and initializes it with the provided expression result. After initializing with a value, the range variable cannot be used to store another value. However, if the range variable holds a queryable type, you can query the variable.
Example
Use the following example in two ways let :
Creates an enumerable type that can query itself.
Make the query call only once word on the scope variable ToLower . If not used let , you have to invoke where each predicate in the clause ToLower .
classletsample1{Static voidMain () {string[] strings = { "a penny saved is a penny earned.", "The early bird catches the worm.", "The pen is mightier than the sword." }; //Split The sentence into an array of words//And Select those whose first letter is a vowel. varEarlybirdquery = fromSentenceinchstrings Let words= sentence. Split (' ') fromWordinchwords let W=Word. ToLower ()wherew[0] =='a'|| w[0] =='e'|| w[0] =='I'|| w[0] =='o'|| w[0] =='u' SelectWord; //Execute the query. foreach(varVinchearlybirdquery) {Console.WriteLine ("\ "{0}\" starts with a vowel", V); } //Keep the console window open in debug mode.Console.WriteLine ("Press any key to exit."); Console.readkey (); }}/*Output: ' A ' starts with a vowel ' is ' starts with a vowel ' a ' starts with a vowel ' earned. ' Starts with a Vowel "Early" starts with a vowel ' is ' starts with a vowel*/
C # Reference let clause