This article mainly introduces the let words in C #, the article through the application examples introduced in detail, I believe that we have a certain reference value, the need for friends below to see it together.
First, the application scenario
In query expressions, it is sometimes useful to store the results of a subexpression so that it can be used in subsequent clauses. You can do this with the Let keyword, which creates a new scope variable and initializes the variable with the result of the expression you provide. Once the range variable is initialized with a value, it cannot be used to store other values. However, if the range variable stores a queryable type, it can be queried.
Second, the sample code
Using system;using System.linq;namespace uselet{class Program {static void Main () { string[] strings = { "A Penn Y saved is a penny earned. ", " the early bird catches the worm. ", " the pen is mightier than the sword. " }; 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; foreach (Var v in earlybirdquery) { Console.WriteLine ("\" {0}\ "starts with a vowel", v); } Console.WriteLine ("Press any key to exit"); Console.ReadLine (); } }}
The effect of clause let can be seen from the above effects. If let is not used, you must call ToLower in each predicate of the WHERE clause, and let can save the variables in the from sentence for use.
Summarize
Above is the content of the let sentence application example in C #, more about topic.alibabacloud.com (www.php.cn)!