LINQ learning notes (9) LINQ to objects-query the set of objects in memory

Source: Internet
Author: User

From this article, we should summarize the application of LINQ in practice. The first thing we should summarize is the combination of LINQ to objects, that is, the use of LINQ with program objects.

The most typical application object set is to use it with arrays, as shown in the following example:

1 class Program
2 {
3 static void main (string [] ARGs)
4 {
5 Int [] numbers = {2, 12, 5, 15}; // Data Source
6
7 ienumerable <int> lownums = from N in numbers // define and store the query.
8 where n <10
9 select N;
10
11 foreach (var x in lownums) // use the foreach statement to traverse the set.
12 {
13 console. Write ("{0},", X );
14}
15
16 console. readkey ();
17}
18 /*
19 program output results: 2, 5,
20 */
21}

Through the above example, we found that the steps to implement the query of LINQ to objects are:

1. Create a data source. For example, create an array.

2. Define and store the query.

3. Use the foreach statement to traverse the query results.

The above content is the content of LINQ to objects. It is the simplest and most basic content of LINQ query. The following article will summarize the content of LINQ to entities. I hope you will continue to pay attention to it. Thank you!

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.