Yes, it's true. Pseudo-code below will not work with buildin types (int, long, double and so on) with InvalidCastException.
int[] a = new int[]{ 1, 2, 3 };
IEnumerable<double> d = a.Cast<double>();
foreach (double x in d) {
System.Console.WriteLine(x);
}
To resolve the issue you should rewrite second string with explicit cast as below
IEnumerable<double> d = a.Select(i => (double)i);
No comments:
Post a Comment