Why Enumerable.Cast raises an InvalidCastException?

Well, you have incorrect expectations of Cast, that’s all – it’s meant to deal with boxing/unboxing, reference and identity conversions, and that’s all. It’s unfortunate that the documentation isn’t as clear as it might be 🙁

The solution is to use Select:

doubleNumbers2 = intNumbers.Select(x => (double) x).ToArray();

Leave a Comment