Array of struct A in struct B!

Hi

struct A

{
int x;
int y;
}

struct B
{
int z;
A [] tab=new A[14]; //cannot have instance field initializer in struc ...I know!
}

but i need an array of struct in another struct
thanks.











Answer this question

Array of struct A in struct B!

  • Scorpiuscat

    struct B

    {

    int z;

    A[] tab;

    public B(int z, int tab)

    {

    this.z = z;

    this.tab = new A[tab];

    }

    }



  • Loicus

    tab : 1) is it an array : A[] tab;

    2) or an int : new A[tab];



  • sunarc

    Thanks



  • Rush hour

    struct B

    {

    int z;

    A[] tab;

    public B(int intZ, int tabLenght)

    {

    this.z = intZ;

    this.tab = new A[tabLenght];

    }

    }

    More clear now



  • Lance77035

    Does B have to be a struct If so, can you add a parameterized constructor to it



  • Vinay Agarwal

    1-yes B has to be a struct.

    2-"can you add a parameterized constructor to it" : why not.



  • Array of struct A in struct B!