这是什么类型的阵列?

时间:2014-11-27 01:14:24

标签: c# arrays

我正在使用一个需要以下格式的数组的库:

  var AxisInfo = new object[]
  {
    new {axis = new {_axisName = "Weight", _axisType = "Continuous", _axisId = "115"}},
    new
    {
      MyCustomAttribute1 = "My First Attribute Value",
      MyCustomAttribute2 = "My Second Attribute Value"
    }
  };

首先,这是什么类型的数组?某种嵌套或锯齿状的数组?我之前没有看到像这样定义的数组。 其次,如果你看一下数组{MyCustomAttribute1 = "My First Attribute Value", MyCustomAttribute2 = "My Second Attribute Value"},那么MyCustomAttribute1和MyCustomAttribute2是什么?它们是数组属性还是有其他名称?

最后,有没有办法动态创建像{MyCustomAttribute1 = "My First Attribute Value", MyCustomAttribute2 = "My Second Attribute Value"}这样的数组?我的意思是,如果我有一本字典如下:

Dictionary<string, string> Attributes = new Dictionary<string, string>();
Attributes.Add("MyCustomAttribute1", "My First Attribute Value");
Attributes.Add("MyCustomAttribute2", "My Second Attribute Value");
Attributes.Add("MyCustomAttribute3", "My Third Attribute Value");
Attributes.Add("MyCustomAttribute4", "My Fourth Attribute Value");
Attributes.Add("MyCustomAttribute5", "My Fifth Attribute Value");

我可以将其转换为这样的数组:

{MyCustomAttribute1 = "My First Attribute Value", MyCustomAttribute2 = "My Second Attribute Value", MyCustomAttribute3 = "My Third Attribute Value",MyCustomAttribute4 = "My Fourth Attribute Value",MyCustomAttribute5 = "My Fifth Attribute Value"}

0 个答案:

没有答案