A few small examples of linq and a small example of linq

Source: Internet
Author: User

A few small examples of linq and a small example of linq

Private void button#click (object sender, EventArgs e) {int [] numbers = new int [7] {0, 1, 2, 3, 4, 5, 6 }; var result0 = from num in numbers where (num % 2 = 0) select num; foreach (int n in result0) {listBox1.Items. add (n) ;}} private void button2_Click (object sender, EventArgs e) {listBox1.Items. clear (); int [] numbers = new int [7] {2, 3, 4, 3, 5 }; var result1 = from num in numbers where num> 3 orderby num descending select num; foreach (int n in result1) {listBox1.Items. add (n) ;}} private void button3_Click (object sender, EventArgs e) {listBox1.Items. clear (); int [] numbers = new int [7] {2, 3, 2, 4, 3, 5, 5 }; var result2 = from num in numbers where num> 3 orderby num ascending select string. format ("Current Value: {0}", num); foreach (string n in result2) {listBox1.Items. add (n) ;}} private void button4_Click (object sender, EventArgs e) {listBox1.Items. clear (); int [] numbers = new int [7] {2, 3, 2, 4, 3, 5, 5 }; int result3 = (from num in numbers where num> 3 select num ). count (); button4.Text + = "--" + result3.ToString ();}

 

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.