Several traversal implementations of Dictionary in C

  • 2020-05-26 08:16:20
  • OfStack


 Dictionary<string,string> list=new Dictionary<string,string>;
//3.0 The above version 
foreach(var item in list)
{
      Console.WriteLine(item.Key+item.Value);
}
//KeyValuePair<T,K>
foreach(KeyValuePair<string,string> kv in list)
{
      Console.WriteLine(kv.Key+kv.Value);
}
// Fetch through the set of keys 
foreach(string key in list.Keys)
{
      Console.WriteLine(key+list[key]);
}
//for To iterate over 
List<string> test=new List<string>(list.Keys);
for(int i=0;i<list.Count;i++)
{
      Console.WriteLine(test[i]+list[test[i]]);
}
 

Related articles: