These operators provide the capability to express query operations directly and declaratively within
any .NET-based programming language. What makes all of this possible is the simple application of the
query operators to an IEnumerable
source of information.
Found in the System.Collections.Generic namespace, the IEnumerable interface, a new addition
in version 2.0 of the .NET Framework, supports a simple iteration over a collection of a given (specified)
type. The IEnumerable interface provides a slick mechanism to iterate through an arbitrary collection
of strongly typed objects using the C# foreach statement or the Visual Basic FOR EACH statement. To
utilize the foreach semantics, this interface must be implemented.
So the question is, what does this mean for LINQ? It means that a query that implements this interface can
be a source for the corresponding query expression. You saw several examples of this at the beginning of
this chapter, and the best way to understand the LINQ technology is to see it in action.
The following example utilizes LINQ, a few standard query operators, and the IEnumerable interface
to query and process the contents within a defined array:
private void ShowLINQ()
{
string[] firstnames = { "Scott", "Steve", "Ken", "Joe", "John",
"Alex", "Chuck", "Sarah"};
IEnumerable val = from fn in firstnames
where fn.
Pages:
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42