C # Reference let clause

Source: Internet
Author: User

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 :

    1. Creates an enumerable type that can query itself.

    2. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.