Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Casting of int array into double array in immediate window?

Is it possible to cast int array into double array in immediate window? I tried to cast but somehow its not working. I would like to know that is it possible or not?

like image 557
User1551892 Avatar asked Feb 19 '14 14:02

User1551892


2 Answers

That cast is illegal. Just try to compile it and you will see that it doesn't work either.

The following code will perform this conversion:

var d = i.Select(x => (double)x).ToArray();

Unfortunately, you can't use it in the immediate window because it doesn't support lambda expressions.

A solution that doesn't require lambda expressions is the following:

i.Select(Convert.ToDouble).ToArray();

This could work because there is no lambda expression. Thanks to Chris for the idea.

like image 115
Daniel Hilgarth Avatar answered Nov 18 '22 02:11

Daniel Hilgarth


One more way is to use Array.ConvertAll

Array.ConvertAll<int, double>(nums, x => x);
like image 42
volody Avatar answered Nov 18 '22 01:11

volody