【C#学习笔记】Dictionary容器使用

using System;
using System.Collections.Generic;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            Dictionary<string, int> a = new Dictionary<string, int>();

            a.Add("xiaoming", 10);
            a["xiaozhang"] = 11;
            a.Add("xiaoli", 12);

            foreach (KeyValuePair<string, int> i in a)
            {
                Console.Write(i.Key + ":" + i.Value);
                Console.WriteLine();
            }
            Console.WriteLine();

            a.Remove("xiaoming");
            foreach (KeyValuePair<string, int> i in a)
            {
                Console.Write(i.Key + ":" + i.Value);
                Console.WriteLine();
            }

            a.ContainsKey("xiaoli");    //返回bool
            a.ContainsValue(11);        //返回bool
            int s = a["xiaozhang"];
            Console.Write(s);

            Console.Read();
        }      
    }
}

 

posted @ 2017-08-27 15:07  Dsp Tian  阅读(719)  评论(0编辑  收藏  举报