【发布时间】:2016-11-25 05:16:10
【问题描述】:
我有一个Dictionary,它有一个 ID 作为键,一个列表作为值。我想知道列表中有多少列表。当我在调试时查询它时,这似乎给出了正确的值,但是当我尝试访问该数据时,它只给出 1 而不是 2 的计数。我确定这是我缺少的东西,但我不能放我的手指在它上面。
整个方法是:
public static List<string> getStatisticsCSVHeaders(List<Items> itemList, Dictionary<int, List<List<Statistic>>> availableStats)
{
List<string> topRow = new List<string>();
for (int i = 0; i < availableStats.Values.Count; i++)
{
topRow.Add("Phase " + (i+1));
for (int k = 0; k < itemList.Count; k++)
topRow.Add(getMetricHeader(itemList[k], true));
}
return topRow;
}
我想将列表中的列表数作为i < availableStats.Values.Count 行的计数器。
编辑:
我应该提到我已经尝试过availableStats.Values[0].Count,但这不会编译。
【问题讨论】:
-
你试过
foreach(var list in YourDictionary.Value) { // .. } -
为什么不可用Stats.Count()?
-
@Prashant 或者
availableStats.Value.Count()? -
字典上没有 Value.Count()。
标签: c# debugging for-loop dictionary