内部に辞書を含む配列リストをループしたい。
foreach(Dictionary<string, string> tempDic in rootNode)
{
Response.Write(tempDic.key + "," tempDic.value + "<br>");
}
辞書のキーと値にアクセスするには?
tempDic
また、辞書内でループする必要があり、そのためにusing を繰り返すことができますForeach
。
foreach(Dictionary<string, string> tempDic in rootNode)
{
foreach(KeyValuePair<string, string> _x in tempDic)
{
Response.Write(_x.key + "," + _x.value + "<br>");
}
}
IEnumerable<KeyValuePair<string, string>>
最初に LINQ を使用して、(実際には) すべてKeyValuePair
の s のリストを取得できます。
var pairs = rootNode.OfType<Dictionary<string, string>>()
.SelectMany(d => d.AsEnumerable());
foreach (KeyValuePair<string, string> tempPair in pairs)
{
Response.Write(tempPair.Key + "," + tempPair.Value + "<br>");
}
したがって、foreach ループを 1 回実行するだけで十分です。もう 1 つは LINQ によって行われます。