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


C# OrderedDictionary.GetEnumerator方法代码示例

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


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

示例1: Common

		private void Common (OrderedDictionary od)
		{
			Assert.IsNotNull (od.GetEnumerator (), "GetEnumerator");
			Assert.AreEqual (0, od.Count, "Count-0");
			Assert.IsFalse (od.IsReadOnly, "IsReadOnly");
			od.Add ("a", "1");
			Assert.AreEqual (1, od.Count, "Count-1");
			od["a"] = "11";
			Assert.AreEqual ("11", od["a"], "this[string]");
			od[0] = "111";
			Assert.AreEqual ("111", od[0], "this[int]");

			DictionaryEntry[] array = new DictionaryEntry[2];
			od.CopyTo (array, 1);

			Assert.AreEqual ("111", ((DictionaryEntry)array[1]).Value, "CopyTo");
			Assert.AreEqual (1, od.Keys.Count, "Keys");
			Assert.AreEqual (1, od.Values.Count, "Values");
			Assert.IsTrue (od.Contains ("a"), "Contains(a)");
			Assert.IsFalse (od.Contains ("111"), "Contains(111)");

			od.Insert (0, "b", "2");
			Assert.AreEqual (2, od.Count, "Count-2");
			od.Add ("c", "3");
			Assert.AreEqual (3, od.Count, "Count-3");

			OrderedDictionary ro = od.AsReadOnly ();

			od.RemoveAt (2);
			Assert.AreEqual (2, od.Count, "Count-4");
			Assert.IsFalse (od.Contains ("c"), "Contains(c)");

			od.Remove ("b");
			Assert.AreEqual (1, od.Count, "Count-5");
			Assert.IsFalse (od.Contains ("b"), "Contains(b)");

			od.Clear ();
			Assert.AreEqual (0, od.Count, "Count-6");

			Assert.IsTrue (ro.IsReadOnly, "IsReadOnly-2");
			// it's a read-only reference
			Assert.AreEqual (0, od.Count, "Count-7");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:43,代码来源:OrderedDictionaryTest.cs

示例2: DetailsView_ExtractRowValues

		public void DetailsView_ExtractRowValues ()
		{
			PokerDetailsView dv = new PokerDetailsView ();
			DataTable ds = TableObject.CreateDataTable ();
			dv.DataSource = ds;
			dv.DataBind ();
			OrderedDictionary fieldsValues = new OrderedDictionary ();
			dv.DoExtractRowValues (fieldsValues, true, true);
			Assert.AreEqual (3, fieldsValues.Count, "ExtractRowValues1");
			Assert.AreEqual (3, fieldsValues.Keys.Count, "ExtractRowValues2");
			Assert.AreEqual (3, fieldsValues.Values.Count, "ExtractRowValues3");
			Assert.AreEqual (true, fieldsValues.Contains ("ID"), "ExtractRowValues4");
			IDictionaryEnumerator enumerator=fieldsValues.GetEnumerator ();
			enumerator.MoveNext ();
			Assert.AreEqual ("ID",enumerator.Key,"FieldValue1");
			Assert.AreEqual ("1001", enumerator.Value , "FieldValue2");
			enumerator.MoveNext ();
			Assert.AreEqual ("FName", enumerator.Key, "FieldValue3");
			Assert.AreEqual ("Mahesh", enumerator.Value, "FieldValue4");
			enumerator.MoveNext ();
			Assert.AreEqual ("LName", enumerator.Key, "FieldValue5");
			Assert.AreEqual ("Chand", enumerator.Value, "FieldValue6");
			fieldsValues = new OrderedDictionary ();
			dv.DoExtractRowValues (fieldsValues, false, false);
			Assert.AreEqual (0, fieldsValues.Count, "ExtractRowValues-NotReadOnly1");
			fieldsValues = new OrderedDictionary ();
			dv.DoExtractRowValues (fieldsValues, true, false);
			Assert.AreEqual (3, fieldsValues.Count, "ExtractRowValues-NoPrimaryKeys1");
			Assert.AreEqual (3, fieldsValues.Keys.Count, "ExtractRowValues-NoPrimaryKeys2");
			fieldsValues = new OrderedDictionary ();
			dv.DoExtractRowValues (fieldsValues, false, true);
			Assert.AreEqual (0, fieldsValues.Count, "ExtractRowValues-NotReadOnly2");
			Assert.AreEqual (0, fieldsValues.Keys.Count, "ExtractRowValues-NotReadOnly3");
		}
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:34,代码来源:DetailsViewTest.cs

示例3: GetEnumeratorTests

 public void GetEnumeratorTests()
 {
     var d = new OrderedDictionary();
     IEnumerator e = d.GetEnumerator();
     d["foo"] = "bar";
     Assert.Throws<InvalidOperationException>(() => e.MoveNext());
     e = d.GetEnumerator();
     Assert.True(e.MoveNext());
     var c = (DictionaryEntry)e.Current;
     Assert.Equal("foo", c.Key);
     Assert.Equal("bar", c.Value);
     Assert.False(e.MoveNext());
 }
开发者ID:rajeevkb,项目名称:corefx,代码行数:13,代码来源:OrderedDictionaryTests.cs

示例4: GetDictionaryEnumeratorTests

        public void GetDictionaryEnumeratorTests()
        {
            var d = new OrderedDictionary();
            for (int i = 0; i < 10; i++)
            {
                d.Add("Key_" + i, "Value_" + i);
            }

            IDictionaryEnumerator e = d.GetEnumerator();
            for (int i = 0; i < 2; i++)
            {
                int count = 0;
                while (e.MoveNext())
                {
                    DictionaryEntry entry1 = (DictionaryEntry)e.Current;
                    DictionaryEntry entry2 = e.Entry;

                    Assert.Equal(entry1.Key, entry2.Key);
                    Assert.Equal(entry1.Value, entry1.Value);

                    Assert.Equal(e.Key, entry1.Key);
                    Assert.Equal(e.Value, entry1.Value);

                    Assert.Equal(e.Value, d[e.Key]);
                    count++;
                }
                Assert.Equal(count, d.Count);
                Assert.False(e.MoveNext());
                e.Reset();
            }

            e = d.GetEnumerator();
            d["foo"] = "bar";
            Assert.Throws<InvalidOperationException>(() => e.MoveNext());
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:35,代码来源:OrderedDictionaryTests.cs


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