int
called
nums
is declared. All arrays in C# are implicitly convertible
to
IEnumerable
. This makes any C# array usable as a LINQ data source.
Next, a query is declared that retrieves those elements in
nums
that are positive. It is
shown here:
var posNums = from n in nums
where n > 0
select n;
The variable
posNums
is called the
query variable.
It refers to the set of rules defined by the
query. Notice it uses
var
to implicitly declare
posNums
. As you know, this makes
posNums
an implicitly typed variable. In queries, it is often convenient to use implicitly typed
variables, although you can also explicitly declare the type (which must be some form
of
Do'stlaringiz bilan baham: |