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


C# OrderedDictionary.IndexOf方法代码示例

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


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

        public void IndexOf_StartIndex_KeyNull()
        {
            var dict = new OrderedDictionary<string, int>();
            dict.Add("foo", 0);
            dict.Add("bar", 1);
            dict.Add("baz", 2);
            dict.Add("monkeys", 3);

            dict.IndexOf (null, 1);
        }
开发者ID:mono,项目名称:rocks,代码行数:10,代码来源:OrderedDictionaryTest.cs

示例3: IndexOf_StartIndex_NotFound

        public void IndexOf_StartIndex_NotFound()
        {
            var dict = new OrderedDictionary<string, int>();
            dict.Add("foo", 0);
            dict.Add("bar", 1);
            dict.Add("baz", 2);
            dict.Add("monkeys", 3);

            Assert.AreEqual (-1, dict.IndexOf ("asdf", 2));
            Assert.AreEqual (-1, dict.IndexOf ("bar", 2));
        }
开发者ID:mono,项目名称:rocks,代码行数:11,代码来源:OrderedDictionaryTest.cs

示例4: IndexOf_StartIndex_IndexOutOfRangeUpper

        public void IndexOf_StartIndex_IndexOutOfRangeUpper()
        {
            var dict = new OrderedDictionary<string, int>();
            dict.Add("foo", 0);
            dict.Add("bar", 1);
            dict.Add("baz", 2);
            dict.Add("monkeys", 3);

            dict.IndexOf("monkeys", 5);
        }
开发者ID:mono,项目名称:rocks,代码行数:10,代码来源:OrderedDictionaryTest.cs

示例5: IndexOf_StartIndexAndCount_CountOutOfRange

        public void IndexOf_StartIndexAndCount_CountOutOfRange()
        {
            var dict = new OrderedDictionary<string, int>();
            dict.Add("foo", 0);
            dict.Add("bar", 1);
            dict.Add("baz", 2);
            dict.Add("monkeys", 3);

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

示例6: IndexOf_StartIndexAndCount

        public void IndexOf_StartIndexAndCount()
        {
            var dict = new OrderedDictionary<string, int>();
            dict.Add("foo", 0);
            dict.Add("bar", 1);
            dict.Add("baz", 2);
            dict.Add("monkeys", 3);

            Assert.AreEqual(1, dict.IndexOf("bar", 1, 1));
            Assert.AreEqual(2, dict.IndexOf("baz", 0, 3));
        }
开发者ID:mono,项目名称:rocks,代码行数:11,代码来源:OrderedDictionaryTest.cs

示例7: IndexOf_NotFound

        public void IndexOf_NotFound()
        {
            var dict = new OrderedDictionary<string, int>();
            dict.Add("foo", 0);
            dict.Add("bar", 1);

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

示例8: IndexOf_KeyNull

        public void IndexOf_KeyNull()
        {
            var dict = new OrderedDictionary<string, int>();
            dict.Add("foo", 0);
            dict.Add("bar", 1);

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


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