TakeWhile, TakeWhile, and linqtakewhile in Linq

Source: Internet
Author: User

TakeWhile, TakeWhile, and linqtakewhile in Linq

These two concepts are easy to confuse and understand. Then I will write them here to facilitate memory.

 

 

SkipWhile can be understood as if the condition is met, it will always skip and retrieve all the remaining elements after knowing that the condition is not met (the remaining elements will not be judged)

TakeWhile can be understood as if the condition is met, the value is always valid until it is not met and all the remaining elements are lost (the latter will not be judged)

 

Int [] intAry = {2, 4, 5, 8, 9, 11, 10, 20, 15, 45, 78, 80}; var query = intAry. takeWhile (num => num % 2 = 0); var query1 = intAry. skipWhile (num => num % 2 = 0); // query: 2 4 // query1: 5, 8, 9, 11, 10, 20, 15, 45, 78, 80

Related Article

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.