I would like to understand how to initialize array object from an outside class. Please refer to the code below:
Class C
{
private string name { get; set; }
private string value { get; set; }
}
Class B
{
private C[] field;
public C[] Field { get; set; };
}
Class Program
{
public static void Main(string[] args)
{
B b = new B();
/* my question was how to initialize this array object inside B class */
b.Field = new C[1];
b.Field[0] = new C();
/* Now I can access b.Field[0].name */
}
}
Note that I cannot change Classes B and C as they are already provided to me. Thanks for your help.