description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid | ||||
---|---|---|---|---|---|---|---|---|---|
let clause - C# Reference |
let clause |
07/20/2015 |
|
|
13c9c1a4-ce57-48ef-8e1b-4c2a59b99fb4 |
In a query expression, it's sometimes useful to store the result of a subexpression 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. Once initialized with a value, the range variable can't be used to store another value. However, if the range variable holds a queryable type, it can be queried.
In the following example let
is used in two ways:
-
To create an enumerable type that can itself be queried.
-
To enable the query to call
ToLower
only one time on the range variableword
. Without usinglet
, you would have to callToLower
in each predicate in thewhere
clause.
[!code-csharpcscsrefQueryKeywords#28]