[英]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. 我使用的是视觉基础库,并且使用的方法之一是将System.Array传递给它的调用。 I've tried using "double[]" and "Object[]" when declaring my array however those will not pass.
我在声明我的数组时尝试使用“ double []”和“ Object []”,但是它们不会通过。 I'm not sure how to convert/declare a "System.Array".
我不确定如何转换/声明“ System.Array”。
Object[] filledVals = new Object[9];
xyz.getDoubleArray("NumVoids", out filledVals); //where .getDoubleArray(string, System.Array)
You can use LINQ: 您可以使用LINQ:
System.Array result;
xyz.getDoubleArray("NumVoids", out result);
var filledVals = result.OfType<double>().ToArray();
Simply declare it as System.Array
: 只需将其声明为
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
. 由于它是
out
参数,因此不需要初始化它,因为它必须由getDoubleArray
初始化。
To convert it to a double[]
you can use this: 要将其转换为
double[]
,可以使用以下命令:
double[] result = filledVals.OfType<double>().ToArray();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.