Simple example of scenario I am trying to implement
class ATest
{
int a;
int b;
BTest[];
}
class BTest
{
int X;
int Y;
}
- I need to create
ATestandBTestdynamically based on a value. - I tried it as
Atest[] aobj = new Atest[count];(This count value will be set programmatically) - Now I need to create Array of Objects of
Bdynamically and assign it toA -
Currently I assume static value for count and assigned it
Atest[] aobj = new Atest[20]; BTest[] bobj = new BTest[1]; bobj[0] = new Btest(); aobj[0] = new ATest(); aobj[0].BTest = bobj; BTest[] bobj1 = new BTest[1]; bobj1[0] = new Btest(); aobj1[0].BTest = bobj1;
This may not be the best way to code.
Please suggest on dynamically implementing it
– Dynamically create number of BTest object arrays and assign it for ATest instances
Try using constructors:
The you can create and initialize your atests in a simple loop: