简体   繁体   中英

Convert double[] to System.array c#

I'm using a visual basic library and one of the methods I'm using calls for a System.Array to be passed into it. I've tried using "double[]" and "Object[]" when declaring my array however those will not pass. I'm not sure how to convert/declare a "System.Array".

Object[] filledVals = new Object[9];                   
xyz.getDoubleArray("NumVoids", out filledVals); //where .getDoubleArray(string, System.Array)

You can use LINQ:

System.Array result;              
xyz.getDoubleArray("NumVoids", out result);
var filledVals = result.OfType<double>().ToArray();

Simply declare it as System.Array :

Array filledVals;
xyz.getDoubleArray("NumVoids", out filledVals); 

Since it is an out parameter, you don't need to initialize it as it must be initialized by getDoubleArray .

To convert it to a double[] you can use this:

double[] result = filledVals.OfType<double>().ToArray();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM