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!