如何创建一系列名为object(x)
的对象,其中x
是一个数字?像是
int x = 1;
Object object(x) = new Object();
每个答案都将受到赞赏!
答案 0 :(得分:1)
我建议使用接近所需语法的Dictionary<int, Object>
:
int x = 1;
// If you insist on object as a name you have to use @ prefix
// since object is a reserved word
Dictionary<int, Object> @object = new Dictionary<int, object>();
@object.Add(1, new object());
...
// If you want to access the istance use @object[x]
object myObject = @object[x];