c# for循环获取dictionary的键和值

protected void Button1_Click ( object sender, EventArgs e )
        {
            Dictionary<string, string> DicTest = new Dictionary<string, string>();
            DicTest.Add( "a", "1" );
            DicTest.Add( "b", "2" );
            DicTest.Add( "c", "3" );
            DicTest.Add( "d", "4" );
            DicTest.Add( "e", "5" );
            DicTest.Add( "f", "6" );

            for(int i = 0 ; i < DicTest.Count ; i++)
            {
                Literal1.Text += DicTest.ToList()[i].Key + ":" + DicTest.ToList()[i].Value+ "<br/>";
            }
        }

前台图片:

后台展示:

原文地址:https://www.cnblogs.com/zhanglimei/p/4010837.html