以下是一个示例代码,演示如何遍历List
List> listOfDictionaries = new List>();
// 添加一些示例数据到List
Dictionary dictionary1 = new Dictionary();
dictionary1.Add("Key1", "Value1");
dictionary1.Add("Key2", "Value2");
listOfDictionaries.Add(dictionary1);
Dictionary dictionary2 = new Dictionary();
dictionary2.Add("Key1", "Value3");
dictionary2.Add("Key2", "Value4");
listOfDictionaries.Add(dictionary2);
// 遍历List并获取值
foreach (Dictionary dictionary in listOfDictionaries)
{
foreach (KeyValuePair pair in dictionary)
{
string key = pair.Key;
string value = pair.Value;
Console.WriteLine("Key: " + key + ", Value: " + value);
}
}
这段代码首先创建了一个List
然后,通过两个嵌套的foreach循环,遍历List
你可以根据需要修改代码来适应你的数据结构和具体操作。
上一篇:遍历“hover”函数
下一篇:遍历“循环”数组