字典 d (int knum, string)
里面放了好多组现在怎么判断某个key,是否在d里呢?

解决方案 »

  1.   

    if(d.ContainsKey(key)){
    存在处理
    }
    else
    {
    不存在处理
    }
      

  2.   


     Dictionary<string, string> dic = new Dictionary<string, string>();
                dic.Add("1","A1");
                dic.Add("2", "A1");
                dic.Add("3", "A1");
                //是否包含1这个key
                if(dic.ContainsKey("1"))
                {
                    Console.WriteLine("存在");
                }
                //遍历Key
                foreach(string key in dic.Keys)
                {
                    Console.WriteLine(key);
                }