private void button1_Click(object sender, EventArgs e)
 {
            Dictionary<string, string> List = new Dictionary<string, string>();
            List.Add("1", "A");
            List.Add("2", "B");
            List.Add("3", "C");
            List.Add("4", "D");
            List.Add("5", "E");
            List.Add("6", "F");
            List.Add("7", "G");
            List.Add("8", "H");

            //方法一
            foreach (var item in List)
            {
                Console.WriteLine(item.Key + " , " + item.Value);
            }

            //方法二
            foreach (KeyValuePair<string, string> item in List)
            {
                Console.WriteLine(item.Key + " , " + item.Value);
            }

            //方法三
            foreach (string key in List.Keys)
            {
                Console.WriteLine(key + " , " + List[key]);
            }

  }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-29
  • 2022-12-23
  • 2022-02-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案