如何将System.Object [*]转换为System.Object [] [英] How to cast System.Object[*] to System.Object[]
问题描述
当我试图返回一个 Array
在VFP9语言COM / DLL到我的.NET C#项目
我收到一个系统。对象[*]
数组,我不能转换为 System.Object []
(没有星号)。
Timwi的解决方案应该可以正常工作。你可以使用Linq做一些简单的事情:
object [] newArray = sourceArray.Cast< object>()。ToArray );
如果您需要重新创建 System.Object [*] code>将其传回VFP,您可以使用此重载<>> c> c> c> CreateInstance(
Type elementType,
int [] lengths,
int [] lowerBounds
)
您可以使用它如下:
object [] normalArray = ...
//创建下边界为1的数组
数组arrayStartingAt1 =
Array.CreateInstance(
typeof(object),
new [] {normalArray。 Length},
new [] {1});
Array.Copy(normalArray,0,arrayStartingAt1,1,normalArray.Length);
When I Tried to return an Array
in VFP9 language COM/DLL to my .NET C# project
I receive a System.Object[*]
array and I can not cast to System.Object[]
(Without asterisk).
Timwi's solution should work fine. You can do something a bit simpler using Linq:
object[] newArray = sourceArray.Cast<object>().ToArray();
In case you need to recreate a System.Object[*]
to pass it back to VFP, you can use this overload of the Array.CreateInstance
method:
public static Array CreateInstance(
Type elementType,
int[] lengths,
int[] lowerBounds
)
You can use it as follows:
object[] normalArray = ...
// create array with lower bound of 1
Array arrayStartingAt1 =
Array.CreateInstance(
typeof(object),
new[] { normalArray.Length },
new[] { 1 });
Array.Copy(normalArray, 0, arrayStartingAt1, 1, normalArray.Length);
这篇关于如何将System.Object [*]转换为System.Object []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!