0

I have a Labview interop assembly which wants string[* ], int[* ] and customType[*] for various structs and methods.

For example, this is the declaration of a struct in the metadata:

public struct AppImage__32Properties
{
   ...
    public FPGA__32Properties[] fPGA__32Properties;
...}

fPGA__32Properties is an array of struct.

Now I want to assign to it an empty array of the same type (Its instance is not initialized) and then proceed with filling its fields.

AppInfoDummy[0].appImage__32Properties.fPGA__32Properties =  
          new FPGA__32Properties[1];   

but it results in

"Cannot implicitly convert type 'DeployImage_RAD.FPGA_32Properties[]' to DeployImage_RAD.FPGA_32Properties[*]".

I have the same problem with other struct, int and string arrays of type [*] from that interop assembly.

Apparently someType[*] is an array which has its starting index somewhere else than zero. ( What does System.Double[*] mean) and there is a way to access it values. But how do I assign a value to it?

BTW: I worked on this project in Visual Studio 2012 Profession before and this problem did not occur. Now I use Visual Studio 2015 Prof.

Community
  • 1
  • 1
Simorgh
  • 61
  • 1
  • 11

1 Answers1

2

You need to use the Array class directly. C# can't really help you much in this case (VB.NET will make this a lot easier, since it supports custom lower and higher bounds natively, unlike C#).

As a sample, if you need a double array going from 1 to 10, it would be defined as:

Array doubleArray = Array.CreateInstance(typeof(double), new []{ 10 }, new []{ 1 });

Accessing an index also goes through Array:

doubleArray.SetValue(42d, 3); // Set value 42d at index 3
doubleArray.GetValue(3); // Get value at index 3 (offset 2 in this case)

It might be a good idea to make a safe wrapper around (or a statically typed copy of) the Array instance, just to make it easier to work with, and more explicit which Array is which.

Luaan
  • 62,244
  • 7
  • 97
  • 116
  • Thanks Luaan. Visual Studio accepts this and I can build the solution. However, I couldn't get to test it yet because I have another problem with string[*] in that code. When I tested it successfully, I will mark your answer. – Simorgh Mar 03 '17 at 15:32
  • Hi Luaan, I cannot create an instance of type string[ * ] with Array.CreateInstance. Some of those arrays are string[ * ]. – Simorgh Mar 08 '17 at 12:31
  • @Simorgh It works fine for me. Are you having trouble initializing the values in the string array? Are you getting some exception? – Luaan Mar 08 '17 at 14:10