Please help with managed array syntax

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Roy Chastain

    #1

    Please help with managed array syntax

    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_tabl e []) __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.

    -------------------------------------------
    Roy Chastain
    KMSystems, Inc.
  • Markus Minichmayr

    #2
    Re: Please help with managed array syntax

    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


    "Roy Chastain" <NOSPAMroy@kmsy s.com.NOSpam> schrieb im Newsbeitrag
    news:ti6210l0k2 jr70n84ifraron7 hj2qitcou@4ax.c om...[color=blue]
    > 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_tabl e []) __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.
    >
    > -------------------------------------------
    > Roy Chastain
    > KMSystems, Inc.[/color]


    Comment

    • Keiji Oenoki

      #3
      RE: Please help with managed array syntax

      > Now, in MC++ would like to delcare a static enity that would be an[color=blue]
      > array of pointers to array1, array2 ... arrayn.[/color]

      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.

      --
      Keiji Oenoki
      Visual C++ Team
      This posting is provided AS IS with no warranties, and confers no rights.

      Comment

      Working...