.net 字典的速学

        private void Form1_Load(object sender, EventArgs e)
{
var myDict = new Dictionary<string, string>();
myDict.Add("1", "中国");
myDict.Add("2", "美国");
myDict.Add("3", "俄罗斯");
myDict.Add("4", "日本");

if (!myDict.ContainsKey("5"))
{
MessageBox.Show("5没有");
}

if (myDict.ContainsValue("中国"))
{
MessageBox.Show("有中国哦");
}
MessageBox.Show(myDict["4"]);

myDict["5"] = "新加坡";

if (myDict.ContainsKey("5"))
{
MessageBox.Show("现在有5了");
}

}

一眼理解系列~ 你懂?

posted @ 2011-12-14 23:51  my36z  阅读(337)  评论(0编辑  收藏  举报