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


C# ListDictionary.GetEnumerator方法代码示例

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


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

示例1: BasicTests

		private void BasicTests (ListDictionary ld)
		{
			Assert.AreEqual (0, ld.Count, "Count");
			Assert.IsFalse (ld.IsFixedSize, "IsFixedSize");
			Assert.IsFalse (ld.IsReadOnly, "IsReadOnly");
			Assert.IsFalse (ld.IsSynchronized, "IsSynchronized");
			Assert.AreEqual (0, ld.Keys.Count, "Keys");
			Assert.AreEqual (0, ld.Values.Count, "Values");
			Assert.IsNotNull (ld.SyncRoot, "SyncRoot");
			Assert.IsNotNull (ld.GetEnumerator (), "GetEnumerator");
			Assert.IsNotNull ((ld as IEnumerable).GetEnumerator (), "IEnumerable.GetEnumerator");

			ld.Add ("a", "1");
			Assert.AreEqual (1, ld.Count, "Count-1");
			Assert.IsTrue (ld.Contains ("a"), "Contains(a)");
			Assert.IsFalse (ld.Contains ("1"), "Contains(1)");

			ld.Add ("b", null);
			Assert.AreEqual (2, ld.Count, "Count-2");
			Assert.IsNull (ld["b"], "this[b]");

			DictionaryEntry[] entries = new DictionaryEntry[2];
			ld.CopyTo (entries, 0);

			ld["b"] = "2";
			Assert.AreEqual ("2", ld["b"], "this[b]2");

			ld.Remove ("b");
			Assert.AreEqual (1, ld.Count, "Count-3");
			ld.Clear ();
			Assert.AreEqual (0, ld.Count, "Count-4");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:32,代码来源:ListDictionaryTest.cs

示例2: Test01

        public void Test01()
        {
            ListDictionary ld;
            IDictionaryEnumerator en;

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

            // simple string values
            string[] values =
            {
                "a",
                "aa",
                "",
                " ",
                "text",
                "     spaces",
                "1",
                "$%^#",
                "2222222222222222222222222",
                System.DateTime.Today.ToString(),
                Int32.MaxValue.ToString()
            };

            // keys for simple string values
            string[] keys =
            {
                "zero",
                "one",
                " ",
                "",
                "aa",
                "1",
                System.DateTime.Today.ToString(),
                "$%^#",
                Int32.MaxValue.ToString(),
                "     spaces",
                "2222222222222222222222222"
            };


            // [] ListDictionary GetEnumerator()
            //-----------------------------------------------------------------

            ld = new ListDictionary();

            // [] for empty dictionary
            //
            en = ld.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; });
            //
            //   []  for Filled dictionary
            //
            for (int i = 0; i < values.Length; i++)
            {
                ld.Add(keys[i], values[i]);
            }

            en = ld.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 < ld.Count; i++)
            {
                res = en.MoveNext();
                if (!res)
                {
                    Assert.False(true, string.Format("Error, MoveNext returned false", i));
                }

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

示例3: FxCopyOrMoveDirectory

 private static void FxCopyOrMoveDirectory(CopyOrMove operation, string sourceDirectoryPath, string targetDirectoryPath, bool overwrite)
 {
     if (((operation == CopyOrMove.Move) & !Directory.Exists(targetDirectoryPath)) & IsOnSameDrive(sourceDirectoryPath, targetDirectoryPath))
     {
         Directory.CreateDirectory(GetParentPath(targetDirectoryPath));
         try
         {
             Directory.Move(sourceDirectoryPath, targetDirectoryPath);
             return;
         }
         catch (IOException)
         {
         }
         catch (UnauthorizedAccessException)
         {
         }
     }
     Directory.CreateDirectory(targetDirectoryPath);
     DirectoryNode sourceDirectoryNode = new DirectoryNode(sourceDirectoryPath, targetDirectoryPath);
     ListDictionary exceptions = new ListDictionary();
     CopyOrMoveDirectoryNode(operation, sourceDirectoryNode, overwrite, exceptions);
     if (exceptions.Count > 0)
     {
         IOException exception3 = new IOException(Utils.GetResourceString("IO_CopyMoveRecursive"));
         IDictionaryEnumerator enumerator = exceptions.GetEnumerator();
         while (enumerator.MoveNext())
         {
             DictionaryEntry current = (DictionaryEntry) enumerator.Current;
             exception3.Data.Add(current.Key, current.Value);
         }
         throw exception3;
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:33,代码来源:FileSystem.cs


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