// Get data RIGHT NOW as int[].
int[] subsetAsIntArray =
(from i in numbers where i < 10 select i).ToArray();
// Get data RIGHT NOW as List.
List subsetAsListOfInts =
(from i in numbers where i < 10 select i).ToList();
}
Notice that the entire LINQ expression is wrapped within parentheses to cast it into the correct
underlying type (whatever that may be) in order to call the extension methods of Enumerable.
Also recall from Chapter 10 that when the C# compiler can unambiguously determine the type
parameter of a generic item, you are not required to specify the type parameter. Thus, we could also
call ToArray() (or ToList() for that matter) as follows:
int[] subsetAsIntArray =
(from i in numbers where i < 10 select i).ToArray();
Do'stlaringiz bilan baham: |