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


C# HybridDictionary.GetEnumerator方法代码示例

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


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

示例1: DefaultValues

		public void DefaultValues ()
		{
			HybridDictionary hd = new HybridDictionary (100);
			Assert.AreEqual (0, hd.Count, "Count");
			Assert.IsFalse (hd.IsFixedSize, "IsFixedSize");
			Assert.IsFalse (hd.IsReadOnly, "IsReadOnly");
			Assert.IsFalse (hd.IsSynchronized, "IsSynchronized");
			Assert.AreEqual (0, hd.Keys.Count, "Keys");
			Assert.AreEqual (0, hd.Values.Count, "Values");
			Assert.AreSame (hd, hd.SyncRoot, "SyncRoot");
			Assert.IsNotNull (hd.GetEnumerator (), "GetEnumerator");
			Assert.IsNotNull ((hd as IEnumerable).GetEnumerator (), "IEnumerable.GetEnumerator");
		}
开发者ID:Profit0004,项目名称:mono,代码行数:13,代码来源:HybridDictionaryTest.cs

示例2: Test01

        public void Test01()
        {
            HybridDictionary hd;
            IDictionaryEnumerator en;

            DictionaryEntry curr;        // Enumerator.Current value
            DictionaryEntry de;        // Enumerator.Entry value
            Object k;        // Enumerator.Key value
            Object v;        // Enumerator.Value

            const int BIG_LENGTH = 100;

            // simple string values
            string[] valuesShort =
            {
                "",
                " ",
                "$%^#",
                System.DateTime.Today.ToString(),
                Int32.MaxValue.ToString()
            };

            // keys for simple string values
            string[] keysShort =
            {
                Int32.MaxValue.ToString(),
                " ",
                System.DateTime.Today.ToString(),
                "",
                "$%^#"
            };

            string[] valuesLong = new string[BIG_LENGTH];
            string[] keysLong = new string[BIG_LENGTH];

            for (int i = 0; i < BIG_LENGTH; i++)
            {
                valuesLong[i] = "Item" + i;
                keysLong[i] = "keY" + i;
            }

            // [] HybridDictionary GetEnumerator()
            //-----------------------------------------------------------------

            hd = new HybridDictionary();

            //  [] Enumerator for empty dictionary
            //
            en = hd.GetEnumerator();
            IEnumerator en2;
            en2 = ((IEnumerable)hd).GetEnumerator();
            string type = en.GetType().ToString();
            if (type.IndexOf("Enumerator", 0) == 0)
            {
                Assert.False(true, string.Format("Error, type is not Enumerator"));
            }

            //
            //  MoveNext should return false
            //
            bool res = en.MoveNext();
            if (res)
            {
                Assert.False(true, string.Format("Error, MoveNext returned true"));
            }

            //
            //  Attempt to get Current should result in exception
            //
            Assert.Throws<InvalidOperationException>(() => { curr = (DictionaryEntry)en.Current; });

            //  ---------------------------------------------------------
            //   [] Enumerator for Filled dictionary  - list
            //  ---------------------------------------------------------
            //
            for (int i = 0; i < valuesShort.Length; i++)
            {
                hd.Add(keysShort[i], valuesShort[i]);
            }

            en = hd.GetEnumerator();
            type = en.GetType().ToString();
            if (type.IndexOf("Enumerator", 0) == 0)
            {
                Assert.False(true, string.Format("Error, type is not Enumerator"));
            }

            //
            //  MoveNext should return true
            //

            for (int i = 0; i < hd.Count; i++)
            {
                res = en.MoveNext();
                if (!res)
                {
                    Assert.False(true, string.Format("Error, MoveNext returned false", i));
                }

                curr = (DictionaryEntry)en.Current;
//.........这里部分代码省略.........
开发者ID:er0dr1guez,项目名称:corefx,代码行数:101,代码来源:GetEnumeratorTests.cs

示例3: GetDictionaryEnumerator

        /// <summary>
        /// IDictionary interface that returns an enumerator on the dictionary contents
        /// </summary>
        /// <returns>Returns an enumerator on the dictionary contents</returns>
        protected IDictionaryEnumerator GetDictionaryEnumerator()
        {
            HybridDictionary namespaceTable = new HybridDictionary(_lastDecl);

            for (int thisDecl = 0; thisDecl < _lastDecl; thisDecl++)
            {
                if (_nsDeclarations[thisDecl].Uri != null)
                {
                    namespaceTable[_nsDeclarations[thisDecl].Prefix] = _nsDeclarations[thisDecl].Uri;
                }
            }

            return namespaceTable.GetEnumerator();
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:18,代码来源:XmlnsDictionary.cs

示例4: Test01


//.........这里部分代码省略.........
            {
                // verify that dictionary is copied correctly
                //
                if (String.Compare(hd[keysShort[i]].ToString(), ((DictionaryEntry)destination.GetValue(i + len)).Value.ToString()) != 0)
                {
                    Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i + len)).Value, hd[keysShort[i]]));
                }
                // verify keysShort
                if (String.Compare(keysShort[i], ((DictionaryEntry)destination.GetValue(i + len)).Key.ToString()) != 0)
                {
                    Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i + len)).Key, keysShort[i]));
                }
            }

            //  [] many simple strings and CopyTo(Array, 0)
            //

            hd.Clear();
            cnt = hd.Count;
            len = valuesLong.Length;
            for (int i = 0; i < len; i++)
            {
                hd.Add(keysLong[i], valuesLong[i]);
            }
            if (hd.Count != len)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len));
            }

            destination = Array.CreateInstance(typeof(Object), len);
            hd.CopyTo(destination, 0);
            //
            //
            IDictionaryEnumerator en = hd.GetEnumerator();
            en.MoveNext();
            // items are copied in the same order they are enumerated
            for (int i = 0; i < len; i++)
            {
                // verify that dictionary is copied correctly
                //
                Object k = en.Key;

                if (String.Compare(hd[k].ToString(), ((DictionaryEntry)destination.GetValue(i)).Value.ToString()) != 0)
                {
                    Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Value.ToString(), hd[k]));
                }
                if (String.Compare(k.ToString(), ((DictionaryEntry)destination.GetValue(i)).Key.ToString()) != 0)
                {
                    Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Key.ToString(), k.ToString()));
                }
                en.MoveNext();
            }

            //  [] many simple strings and CopyTo(Array, middle_index)
            //


            hd.Clear();

            hd.Clear();
            len = valuesLong.Length;
            for (int i = 0; i < len; i++)
            {
                hd.Add(keysLong[i], valuesLong[i]);
            }
            if (hd.Count != len)
开发者ID:er0dr1guez,项目名称:corefx,代码行数:67,代码来源:CopyToArrayIntTests.cs


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