當前位置: 首頁>>代碼示例>>C#>>正文


C# HybridDictionary.CopyTo方法代碼示例

本文整理匯總了C#中System.Collections.Specialized.HybridDictionary.CopyTo方法的典型用法代碼示例。如果您正苦於以下問題:C# HybridDictionary.CopyTo方法的具體用法?C# HybridDictionary.CopyTo怎麽用?C# HybridDictionary.CopyTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Collections.Specialized.HybridDictionary的用法示例。


在下文中一共展示了HybridDictionary.CopyTo方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: All

		public void All ()
		{
			HybridDictionary dict = new HybridDictionary (true);
			dict.Add ("CCC", "ccc");
			dict.Add ("BBB", "bbb");
			dict.Add ("fff", "fff");
			dict ["EEE"] = "eee";
			dict ["ddd"] = "ddd";
			
			Assert.AreEqual (5, dict.Count, "#1");
			Assert.AreEqual ("eee", dict["eee"], "#2");
			
			dict.Add ("CCC2", "ccc");
			dict.Add ("BBB2", "bbb");
			dict.Add ("fff2", "fff");
			dict ["EEE2"] = "eee";
			dict ["ddd2"] = "ddd";
			dict ["xxx"] = "xxx";
			dict ["yyy"] = "yyy";

			Assert.AreEqual (12, dict.Count, "#3");
			Assert.AreEqual ("eee", dict["eee"], "#4");

			dict.Remove ("eee");
			Assert.AreEqual (11, dict.Count, "Removed/Count");
			Assert.IsFalse (dict.Contains ("eee"), "Removed/Contains(xxx)");
			DictionaryEntry[] entries = new DictionaryEntry [11];
			dict.CopyTo (entries, 0);

			Assert.IsTrue (dict.Contains ("xxx"), "Contains(xxx)");
			dict.Clear ();
			Assert.AreEqual (0, dict.Count, "Cleared/Count");
			Assert.IsFalse (dict.Contains ("xxx"), "Cleared/Contains(xxx)");
		}
開發者ID:Profit0004,項目名稱:mono,代碼行數:34,代碼來源:HybridDictionaryTest.cs

示例2: Test01

        public void Test01()
        {
            IntlStrings intl;
            HybridDictionary hd;
            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];

            // string [] destination;
            Array destination;

            int cnt = 0;            // Count

            // initialize IntStrings
            intl = new IntlStrings();

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

            // [] HybridDictionary is constructed as expected
            //-----------------------------------------------------------------

            hd = new HybridDictionary();

            // []  Copy empty dictionary into empty array
            //
            destination = Array.CreateInstance(typeof(Object), 0);

            Assert.Throws<ArgumentOutOfRangeException>(() => { hd.CopyTo(destination, -1); });

            hd.CopyTo(destination, 0);

            // exception even when copying empty dictionary
            Assert.Throws<ArgumentException>(() => { hd.CopyTo(destination, 1); });

            //  [] Copy empty dictionary into filled array
            //
            destination = Array.CreateInstance(typeof(Object), valuesShort.Length);
            for (int i = 0; i < valuesShort.Length; i++)
            {
                destination.SetValue(valuesShort[i], i);
            }
            hd.CopyTo(destination, 0);
            if (destination.Length != valuesShort.Length)
            {
                Assert.False(true, string.Format("Error, altered array after copying empty dictionary"));
            }
            if (destination.Length == valuesShort.Length)
            {
                for (int i = 0; i < valuesShort.Length; i++)
                {
                    if (String.Compare(destination.GetValue(i).ToString(), valuesShort[i]) != 0)
                    {
                        Assert.False(true, string.Format("Error, altered item {0} after copying empty dictionary", i));
                    }
                }
            }


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

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

            destination = Array.CreateInstance(typeof(Object), len);
            hd.CopyTo(destination, 0);
//.........這裏部分代碼省略.........
開發者ID:er0dr1guez,項目名稱:corefx,代碼行數:101,代碼來源:CopyToArrayIntTests.cs


注:本文中的System.Collections.Specialized.HybridDictionary.CopyTo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。