我有三个字符串数组:
private readonly string[] PMCTableColumnNames = new string[] { "PMCIP", "Description", "Cam1ReferencePoints", "Cam2ReferencePoints", "DataserverIP" };
private readonly string[] PMDTableColumnNames = new string[] { "PMDIP", "Description" };
private readonly string[] PMDZonesTableColumnNames = new string[] { "PMDIP", "Description", "Zone" };
我想构建一个指向这些数组的数组:
private var[] ArrayReferences = new var[] { PMCTableColumnNames, PMDTableColumnNames, PMDZonesTableColumnNames };
当我将索引放入此(ArrayReferences)数组时,我想获取特定数组的所有元素,如下所示:
string[] _PMDTableColumnNames = ArrayReferences[1];
我该怎么做?
答案 0 :(得分:3)
您可以创建一个数组数组:
private string[][] ArrayReferences;
请注意,您必须在构造函数中初始化ArrayReferences
,因为您无法引用字段初始化程序中的其他数组。即。
public class ClassName
{
private readonly string[] PMCTableColumnNames = new string[] { "PMCIP", "Description", "Cam1ReferencePoints", "Cam2ReferencePoints", "DataserverIP" };
private readonly string[] PMDTableColumnNames = new string[] { "PMDIP", "Description" };
private readonly string[] PMDZonesTableColumnNames = new string[] { "PMDIP", "Description", "Zone" };
private string[][] ArrayReferences;
public ClassName()
{
ArrayReferences = new string[][] { PMCTableColumnNames, PMDTableColumnNames, PMDZonesTableColumnNames };
}
void SomeMethod()
{
string[] _PMDTableColumnNames = ArrayReferences[1];
}
}
答案 1 :(得分:0)
string[][] ArrayReferences = new [] { PMCTableColumnNames, PMDTableColumnNames, PMDZonesTableColumnNames };
或只是
var ArrayReferences = new [] { PMCTableColumnNames, PMDTableColumnNames, PMDZonesTableColumnNames };
应该这样做。
答案 2 :(得分:0)
您只需使用ArrayList类就可以达到这种目的。