Possible Duplicate:
IEnumerable.Cast<>
One can implicitly convert from int to double.
Why does “Specified cast is not valid.” exception is raised here?
double[] a = Enumerable.Range(0, 7).Cast<double>().ToArray();
I have tried several “versions” of it.
P.S. I know possible solutions like:
double[] a = Enumerable.Range(0, 7).Select(x => (double)x).ToArray();
But I’m curious how Cast works => why it doesn’t work in this example which looks so obvious.
Castis made to turn anIEnumerable(untyped) to anIEnumerable<T>(generically typed). It won’t actually differently-cast any of the members.Per this answer:
So, you’re stuck with
.Select().