【问题标题】:.Net Reformat data in the List of List of Sting.Net 重新格式化 Sting 列表中的数据
【发布时间】:2015-05-11 21:00:22
【问题描述】:
我有一个 List(Of List(Of String)。
列表包含这样的数据:
item-A1 item-A2 item-A3
item-B1 item-B2 item-B3
item-C1 item-C2 item-C3
我想以某种方式将其更改为:
item-A1 item-B1 item-C1
item-A2 item-B2 item-C2
item-A3 item-B3 item-C3
有没有办法重新格式化数据并在示例中显示?
任何提示将不胜感激!
【问题讨论】:
标签:
c#
wpf
vb.net
xaml
datagrid
【解决方案1】:
List<List<string>> lstStrings = new List<List<string>>{
new List<string>() {"A1","A2","A3"},
new List<string> {"B1","B2","B3"},
new List<string> {"C1","C2","C3"}
};
List<List<string>> newList = new List<List<string>>();
int j=0;
foreach(String s in lstStrings[0])
{
List<string> innerList = new List<string>();
for(int i=0;i<lstStrings.Count;i++)
{
innerList.Add(lstStrings[i][j]);
}
j++;
newList.Add(innerList);
}
foreach(List<string> lstInner in newList)
{
foreach(string s in lstInner)
{
Console.Write(s);
}
Console.WriteLine();
}
输出
A1B1C1
A2B2C2
A3B3C3