A LINQ clause of the form:
from X x in y
is equivalent to
y.Cast<X>()
and then using x
as the range variable later. The rest of your query is degenerate, so your code is equivalent to:
var intList = floatList.Cast<int>();
Now Enumerable.Cast()
does not do conversions like this - it just does reference conversions and boxing/unboxing conversions. For any other conversions, you need Select
:
var intList = floatList.Select(x => (int) x);
Or if you really to use a query expression:
var intList = from x in floatList select (int) x;
... but personally for simple queries like this, I wouldn't use a query expression - I'd just use the method call as shown above.