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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With