创建对象(n)

时间:2016-12-25 20:21:55

标签: c# object

如何创建一系列名为object(x)的对象,其中x是一个数字?像是

之类的东西
int x = 1;
Object object(x) = new Object();

每个答案都将受到赞赏!

1 个答案:

答案 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];