当前位置: 移动技术网 > IT编程>开发语言>c# > C# Dictionary的使用实例代码

C# Dictionary的使用实例代码

2019年07月18日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下:class dirctonary    {      &nbs

复制代码 代码如下:

class dirctonary
    {
        public void dictionaryget()
        {
            dictionary<int, string> productlist = new system.collections.generic.dictionary<int, string>();
            productlist.add(1, "productionone");
            productlist.add(2, "productiontwo");

            foreach (keyvaluepair<int, string> production in productlist)
            {
                messagebox.show(string.format("{0},{1}", production.key, production.value));
            }
            //messagebox.show(productlist.count.tostring());
            //messagebox.show(productlist[1].tostring());
            dictionary<int, string>.keycollection keys = productlist.keys;
            foreach (var item in keys)
            {
                messagebox.show(item.tostring());
            }

            dictionary<int, string>.valuecollection collection = productlist.values;
            foreach (var item in collection)
            {
                messagebox.show(string.format("{0}", item));
            }
            //productlist.remove(1);
            //productlist.clear();
            messagebox.show("判断是否包含键值对中的键为”1“的值");
            if (productlist.containskey(1))
            {
                messagebox.show(productlist[1]);
            }
            messagebox.show("判断是否包含键值对中的值为”productiontwo“的值");
            if (productlist.containsvalue("productiontwo"))
            {
                messagebox.show(string.format("{0}", "this really exists"));
            }
        }

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网