当前位置: 首页>>代码示例>>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;未经允许,请勿转载。