当前位置: 首页>>代码示例>>C#>>正文


C# OrderedDictionary.Insert方法代码示例

本文整理汇总了C#中OrderedDictionary.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# OrderedDictionary.Insert方法的具体用法?C# OrderedDictionary.Insert怎么用?C# OrderedDictionary.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OrderedDictionary的用法示例。


在下文中一共展示了OrderedDictionary.Insert方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OrderedDictionary

        public void OrderedDictionary()
        {
            OrderedDictionary<string, int> dict = new OrderedDictionary<string, int>();
            DoTests(dict);
            Assert.AreEqual(3, dict. Count, "Has 3 records left");
            Assert.AreEqual(2, dict.IndexOf("test4"), "IndexOf works");
            Assert.AreEqual(dict[1], 30, "Access by numeric index appears to work");
            Assert.AreEqual(dict.Values[1], 30, "Access to values by index is good");
            Assert.AreEqual(dict.Keys[1], "test3", "Access to values by index is good");

            Assert.Throws<NotSupportedException>(Del(()=>{dict.Values[1]=333;}),"Can't set value when accessing it from the Values list");

            dict.Insert(0, 100);

            // indicies should have moved
            Assert.AreEqual(4, dict.Count, "Has 3 records left");
            Assert.AreEqual(3, dict.IndexOf("test4"), "IndexOf works");
            Assert.AreEqual(dict[2], 30, "Access by numeric index appears to work");
            Assert.AreEqual(dict[0], 100);
            // check for autocreated key
            Assert.AreEqual(dict.Keys[0],"0", "Autogenerated a key.");
            dict.Insert(0, 100);
            Assert.AreEqual(dict.Keys[0], "1", "Autogenerated another key.");

        }
开发者ID:emrahoner,项目名称:CsQuery,代码行数:25,代码来源:DictionaryObjects.cs

示例2: Clear

        public void Clear()
        {
            OrderedDictionary<string, string> dictionary = new OrderedDictionary<string, string>();

            List<KeyValuePair<string, string>> tracking = new List<KeyValuePair<string, string>>();
            KeyValuePair<string, string> one = new KeyValuePair<string, string>("1", "one");
            KeyValuePair<string, string> two = new KeyValuePair<string, string>("2", "two");

            dictionary.Add(one);
            dictionary.Insert(0, two);

            Assert.IsTrue(2 == dictionary.Count);

            dictionary.Clear();

            Assert.IsTrue(0 == dictionary.Count);
        }
开发者ID:johndkane,项目名称:GenericOrderedDictionary,代码行数:17,代码来源:OrderedDictionaryTester.cs

示例3: Insert_KeyExists

        public void Insert_KeyExists()
        {
            var dict = new OrderedDictionary<string, int>();
            dict.Add("1", 2);
            dict.Add("3", 4);

            dict.Insert(1, "3", 3);
        }
开发者ID:mono,项目名称:rocks,代码行数:8,代码来源:OrderedDictionaryTest.cs

示例4: Insert

        public void Insert()
        {
            var dict = new OrderedDictionary<string, int>();
            dict.Add ("1", 2);
            dict.Add ("3", 4);

            dict.Insert (1, "2", 3);

            Assert.AreEqual (dict[0], 2);
            Assert.AreEqual (dict[1], 3);
            Assert.AreEqual (dict[2], 4);
        }
开发者ID:mono,项目名称:rocks,代码行数:12,代码来源:OrderedDictionaryTest.cs

示例5: RetrieveByListIndex

        public void RetrieveByListIndex()
        {
            OrderedDictionary<string, string> dictionary = new OrderedDictionary<string, string>();

            dictionary.Add("1", "one");
            dictionary.Insert(0, new KeyValuePair<string, string>("2", "two"));

            Assert.AreEqual(2, dictionary.Count);

            for (int i = 0; i < dictionary.Count; ++i)
            {
                switch (i)
                {
                    case 0:
                        Assert.IsTrue(dictionary[i].Key == "2");
                        break;
                    case 1:
                        Assert.IsTrue(dictionary[i].Key == "1");
                        break;
                    default:
                        Assert.Fail("unexpected element");
                        break;
                }
            }
        }
开发者ID:johndkane,项目名称:GenericOrderedDictionary,代码行数:25,代码来源:OrderedDictionaryTester.cs

示例6: RetrieveByDictionaryKey

        public void RetrieveByDictionaryKey()
        {
            OrderedDictionary<string, string> dictionary = new OrderedDictionary<string, string>();

            dictionary.Add("1", "one");
            dictionary.Insert(0, new KeyValuePair<string, string>("2", "two"));

            Assert.AreEqual("one", dictionary["1"]);
            Assert.AreEqual("two", dictionary["2"]);
        }
开发者ID:johndkane,项目名称:GenericOrderedDictionary,代码行数:10,代码来源:OrderedDictionaryTester.cs

示例7: ItemEnumeration

        public void ItemEnumeration()
        {
            OrderedDictionary<string, string> dictionary = new OrderedDictionary<string, string>();

            List<KeyValuePair<string, string>> tracking = new List<KeyValuePair<string, string>>();
            KeyValuePair<string, string> one = new KeyValuePair<string, string>("1", "one");
            KeyValuePair<string, string> two = new KeyValuePair<string, string>("2", "two");

            int i = 0;

            { // round 1

                dictionary.Add(one);
                dictionary.Insert(0, two);

                // test implicit pairs order
                foreach (KeyValuePair<string, string> item in dictionary)
                {
                    switch (i)
                    {
                        case 0:
                            Assert.AreEqual("2", dictionary[i].Key);
                            break;
                        case 1:
                            Assert.AreEqual("1", dictionary[i].Key);
                            break;
                        default:
                            Assert.Fail("unexpected element");
                            break;
                    }
                    ++i;
                }

                // test explicit pairs order
                i = 0;
                foreach (KeyValuePair<string, string> item in dictionary.GetOrderedPairs())
                {
                    switch (i)
                    {
                        case 0:
                            Assert.AreEqual("2", dictionary[i].Key);
                            break;
                        case 1:
                            Assert.AreEqual("1", dictionary[i].Key);
                            break;
                        default:
                            Assert.Fail("unexpected element");
                            break;
                    }
                    ++i;
                }

                // test keys order
                i = 0;
                foreach (string key in dictionary.GetOrderedKeys())
                {
                    switch (i)
                    {
                        case 0:
                            Assert.AreEqual("2", key);
                            break;
                        case 1:
                            Assert.AreEqual("1", key);
                            break;
                        default:
                            Assert.Fail("unexpected element");
                            break;
                    }
                    ++i;
                }

                // test values order
                i = 0;
                foreach (string key in dictionary.GetOrderedValues())
                {
                    switch (i)
                    {
                        case 0:
                            Assert.AreEqual("two", key);
                            break;
                        case 1:
                            Assert.AreEqual("one", key);
                            break;
                        default:
                            Assert.Fail("unexpected element");
                            break;
                    }
                    ++i;
                }
            }

            dictionary.Clear();
            Assert.AreEqual(0, dictionary.Count);
            i = 0;

            { // round 2

                dictionary.Add(one);
                dictionary.Add(two);

//.........这里部分代码省略.........
开发者ID:johndkane,项目名称:GenericOrderedDictionary,代码行数:101,代码来源:OrderedDictionaryTester.cs


注:本文中的OrderedDictionary.Insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。