C# 如何获取列表中的数据<;阵列>;
例如C# 如何获取列表中的数据<;阵列>;,c#,arrays,.net,winforms,C#,Arrays,.net,Winforms,例如 List<array> thisListOfArray = new List<array>(); List<string> thisArrayA= new List<string>(); List<string> gMaintenanceB = new List<string>(); thisArrayA.Add("ItemA1"); thisArrayA.Add("ItemA2"); thisArrayA.Add("
List<array> thisListOfArray = new List<array>();
List<string> thisArrayA= new List<string>();
List<string> gMaintenanceB = new List<string>();
thisArrayA.Add("ItemA1");
thisArrayA.Add("ItemA2");
thisArrayA.Add("ItemA3");
thisArrayB.Add("ItemB1");
thisArrayB.Add("ItemB2");
thisArrayB.Add("ItemB3");
thisListOfArray.Add(thisArrayA.ToArray());
thisListOfArray.Add(thisArrayB.ToArray());
List thisListOfArray=new List();
List thisaraya=新列表();
List gMaintenanceB=新列表();
本附件a.添加(“第A1项”);
本附件a.添加(“第A2项”);
本附件a.添加(“第A3项”);
本附件B.添加(“项目B1”);
本附件B.添加(“第B2项”);
本附件B.添加(“项目B3”);
添加(thisaraya.ToArray());
添加(thisArrayB.ToArray());
我想获取我在
thisListOfArray
中输入的每个值,更改代码如下:
List<List<string>> thisListOfArray = new List<List<string>>();
List<string> thisArrayA = new List<string>();
List<string> gMaintenanceB = new List<string>();
thisArrayA.Add("ItemA1");
thisArrayA.Add("ItemA2");
thisArrayA.Add("ItemA3");
gMaintenanceB.Add("ItemB1");
gMaintenanceB.Add("ItemB2");
gMaintenanceB.Add("ItemB3");
thisListOfArray.Add(thisArrayA);
thisListOfArray.Add(gMaintenanceB);
foreach (var itm in thisListOfArray.SelectMany(item => item))
{
MessageBox.Show(itm);
}
List thisListOfArray=new List();
List thisaraya=新列表();
List gMaintenanceB=新列表();
本附件a.添加(“第A1项”);
本附件a.添加(“第A2项”);
本附件a.添加(“第A3项”);
gMaintenanceB.添加(“项目B1”);
gMaintenanceB.添加(“项目B2”);
gMaintenanceB.添加(“项目B3”);
thisListOfArray.Add(thisArrayA);
此阵列列表添加(gMaintenanceB);
foreach(此数组列表中的变量itm.SelectMany(item=>item))
{
MessageBox.Show(itm);
}
您可以通过以下方式获得它。这是密码
List<string[]> thisListOfArray = new List<string[]>();
List<string> thisArrayA = new List<string>();
List<string> thisArrayB = new List<string>();
thisArrayA.Add("ItemA1");
thisArrayA.Add("ItemA2");
thisArrayA.Add("ItemA3");
thisArrayB.Add("ItemB1");
thisArrayB.Add("ItemB2");
thisArrayB.Add("ItemB3");
thisListOfArray.Add(thisArrayA.ToArray());
thisListOfArray.Add(thisArrayB.ToArray());
List<string> lstNewstring = new List<string>();
foreach (var strArray in thisListOfArray)
{
foreach (var str in strArray)
{
lstNewstring.Add(str);
}
}
MessageBox.Show(lstNewstring.Count.ToString());
List thisListOfArray=new List();
List thisaraya=新列表();
List thisarayb=新列表();
本附件a.添加(“第A1项”);
本附件a.添加(“第A2项”);
本附件a.添加(“第A3项”);
本附件B.添加(“项目B1”);
本附件B.添加(“第B2项”);
本附件B.添加(“项目B3”);
添加(thisaraya.ToArray());
添加(thisArrayB.ToArray());
List lstNewstring=新列表();
foreach(此列表中的var strArray)
{
foreach(strArray中的var str)
{
lstNewstring.Add(str);
}
}
Show(lstNewstring.Count.ToString());
如果您有:
数组列表
string[]数组
listOfArray.Add(array)将数组添加到列表中代码>
不确定从何处获取数组
。它是C中的列表
。
数组由类型[]
表示。因此,List
需要变成List
。