Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double Array to Object Array?

Tags:

c#

casting

I have following array:

double[] Series = new double[] { 7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6 }

Series debugging view :

> Series
--> [0]
--> [1]
--> ...
--> [10]
--> [11]

When I write following:

object[] object_array = new object[] { Series }

object_array debugging view : (more than one level)

> object_array
--> [0]
----> [0]
----> [1]
----> ...
----> [10]
----> [11]

I write following to prevent new level:

object[] object_array = new object[Series.Length];
for (int i = 0; i < Series.Length; i++)
{
    object_array[i] = Series[i];
}

This is the one of the other solutions. But I think, there may be a better way to do this. Is there a problem for me to use above loop? Or different way?

(I use highcharts. If I give array that contains more than one level, it does not work.)

Thanks.

like image 971
AliRıza Adıyahşi Avatar asked Jul 25 '26 20:07

AliRıza Adıyahşi


1 Answers

var object_array = Series.Cast<object>().ToArray();
like image 120
Eren Ersönmez Avatar answered Jul 27 '26 09:07

Eren Ersönmez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!