Please help with managed array syntax

  • Thread starter Thread starter Roy Chastain
  • Start date Start date
R

Roy Chastain

I have a C# module that defines a type and then makes several arrays
of that type.

public class ArrayEntryType
{ byte member1;
.... ];
public static ArrayEntryType[] array1 = {
new ArrayEntryType(1),
new ArrayEntryType(2)};
public static ArrayEntryType[] array2 = {
new ArrayEntryType(1),
new ArrayEntryType(2)};
etc

Now, in MC++ would like to delcare a static enity that would be an
array of pointers to array1, array2 ... arrayn.

Every combination of defineing the array of pointer to an array that I
try gives me various errors about type conversions etc.

public __gc class ArrayUser {
public:
static ArrayEntryType * (array_ptr_table []) __gc[]; //
this line gives compile error

static ArrayUser (void)
{ array_ptr_table= new ArrayEntryType * [6]; //
note this line needs lots of work
array_ptr_table[0] = &array1;
array_ptr_table[1] = &array2;
}
};

The definition of array_ptr_table is the current problem, but I that
the new will also need help once the definition is correct.

Thanks for you help.
 
Hi Roy!

I also don't know how to correctly solve this problem. However, there are at
least two workarounds I can think of:

1.) If array1, array2, ... are of same size, you could use a 2-dimensional
array:
ArrayEntryType* your2DimArray __gc[,] = __gc new ArrayEntryType[x, y];

2.) You could create an array of Objects, with array1, array2, ... as its
Elements.
Object* yourArray __gc[] = __gc new Object*[x];
yourArray[0] = array1;
yourArray[1] = array2;

To access the subarrays you can cast them back:
ArrayEntryType* arrayN __gc[] = (ArrayEntryType* __gc[]) yourArray[n];

Hope this helps
- Markus
 
Now, in MC++ would like to delcare a static enity that would be an
array of pointers to array1, array2 ... arrayn.

Hello Roy,

Unfortunately array of array (aka "jagged array") is not implemented in
MC++. The latest internal build of the compiler does support this.

Also, a native array (as opposed to managed array) cannot contain managed
type due to the lack of CLR support.
 
Back
Top