IEnumerable.Cast<>

Posted by Renato Person on Stack Overflow See other posts from Stack Overflow or by Renato Person
Published on 2010-05-03T19:57:11Z Indexed on 2010/05/03 20:28 UTC
Read the original article Hit count: 394

Filed under:
|
|

If I can implicitly cast an integer value to a double (and vice versa), like:

int a = 4;    
double b = a;
// now b holds 4.0

Why can I not do this:

int[] intNumbers = {10, 6, 1, 9};    
double[] doubleNumbers2 = intNumbers.Cast<double>().ToArray<double>();

I get an "Specified cast is not valid" error message.

Doing the opposite (casting from double to int) results in the same error.

What am I doing wrong?

© Stack Overflow or respective owner

Related posts about ienumerable

Related posts about cast