當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。