我想了解如何从外部类初始化数组对象。请参考以下代码:
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 */
}
}
请注意,我无法更改 B 类和 C 类,因为它们已经提供给我。谢谢你的帮助。