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


C# ListDictionary.Clear方法代码示例

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


在下文中一共展示了ListDictionary.Clear方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
            int cnt;

            // 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.IsReadOnly should return false
            //-----------------------------------------------------------------

            ld = new ListDictionary();

            //  [] on empty dictionary
            //
            if (ld.IsReadOnly)
            {
                Assert.False(true, string.Format("Error, returned true for empty dictionary"));
            }

            //  [] on filled dictionary
            //

            ld.Clear();
            cnt = values.Length;
            for (int i = 0; i < cnt; i++)
            {
                ld.Add(keys[i], values[i]);
            }
            if (ld.Count != cnt)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", ld.Count, cnt));
            }
            if (ld.IsReadOnly)
            {
                Assert.False(true, string.Format("Error, returned true for filled dictionary"));
            }
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:67,代码来源:GetIsReadOnlyTests.cs

示例3: Test01


//.........这里部分代码省略.........

            for (int i = 0; i < len; i++)
            {
                //
                if (!ld.Contains(intlValues[i + len]))
                {
                    Assert.False(true, string.Format("Error, doesn't contain key", i));
                }
                if (String.Compare(ld[intlValues[i + len]].ToString(), intlValues[i]) != 0)
                {
                    Assert.False(true, string.Format("Error, returned wrong value", i));
                }
            }


            //
            // [] Case sensitivity
            //

            string[] intlValuesLower = new string[len * 2];

            // fill array with unique strings
            //
            for (int i = 0; i < len * 2; i++)
            {
                intlValues[i] = intlValues[i].ToUpper();
            }

            for (int i = 0; i < len * 2; i++)
            {
                intlValuesLower[i] = intlValues[i].ToLower();
            }

            ld.Clear();
            //
            // will use first half of array as values and second half as keys
            //
            for (int i = 0; i < len; i++)
            {
                ld.Add(intlValues[i + len], intlValues[i]);     // adding uppercase strings
            }

            //
            for (int i = 0; i < len; i++)
            {
                // uppercase key
                if (!ld.Contains(intlValues[i + len]))
                {
                    Assert.False(true, string.Format("Error, doesn't contain key", i));
                }

                if (String.Compare(ld[intlValues[i + len]].ToString(), intlValues[i]) != 0)
                {
                    Assert.False(true, string.Format("Error, returned wrong value", i));
                }
            }

            ld.Clear();
            //
            // will use first half of array as values and second half as keys
            //
            for (int i = 0; i < len; i++)
            {
                ld.Add(intlValues[i + len], intlValues[i]);     // adding uppercase strings
            }
开发者ID:noahfalk,项目名称:corefx,代码行数:66,代码来源:GetItemObjTests.cs

示例4: Clear

 public void Clear()
 {
     if (this.hashtable != null)
     {
         Hashtable hashtable = this.hashtable;
         this.hashtable = null;
         hashtable.Clear();
     }
     if (this.list != null)
     {
         ListDictionary list = this.list;
         this.list = null;
         list.Clear();
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:15,代码来源:HybridDictionary.cs

示例5: Test01


//.........这里部分代码省略.........
            {
                //
                cnt = ld.Count;
                ld.Remove(intlValues[i + len]);
                if (ld.Count != cnt - 1)
                {
                    Assert.False(true, string.Format("Error, returned: failed to remove item", i));
                }
                if (ld.Contains(intlValues[i + len]))
                {
                    Assert.False(true, string.Format("Error, removed wrong item", i));
                }
            }


            //
            // [] Case sensitivity
            //

            string[] intlValuesLower = new string[len * 2];

            // fill array with unique strings
            //
            for (int i = 0; i < len * 2; i++)
            {
                intlValues[i] = intlValues[i].ToUpper();
            }

            for (int i = 0; i < len * 2; i++)
            {
                intlValuesLower[i] = intlValues[i].ToLower();
            }

            ld.Clear();
            //
            // will use first half of array as values and second half as keys
            //
            for (int i = 0; i < len; i++)
            {
                ld.Add(intlValues[i + len], intlValues[i]);     // adding uppercase strings
            }

            //
            for (int i = 0; i < len; i++)
            {
                // uppercase key

                cnt = ld.Count;
                ld.Remove(intlValues[i + len]);
                if (ld.Count != cnt - 1)
                {
                    Assert.False(true, string.Format("Error, returned: failed to remove item", i));
                }
                if (ld.Contains(intlValues[i + len]))
                {
                    Assert.False(true, string.Format("Error, removed wrong item", i));
                }
            }

            ld.Clear();
            //
            // will use first half of array as values and second half as keys
            //
            for (int i = 0; i < len; i++)
            {
                ld.Add(intlValues[i + len], intlValues[i]);     // adding uppercase strings
开发者ID:noahfalk,项目名称:corefx,代码行数:67,代码来源:RemoveObjTests.cs

示例6: Test01

        public void Test01()
        {
            IntlStrings intl;


            ListDictionary ld;

            // 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"
            };

            Array arr;
            ICollection ks;         // Keys collection
            int ind;

            // initialize IntStrings
            intl = new IntlStrings();


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

            ld = new ListDictionary();

            //  [] get Keys for empty dictionary
            //
            if (ld.Count > 0)
                ld.Clear();

            if (ld.Keys.Count != 0)
            {
                Assert.False(true, string.Format("Error, returned Keys.Count = {0}", ld.Keys.Count));
            }

            //  [] get Keys for filled dictionary
            //
            int len = values.Length;
            ld.Clear();
            for (int i = 0; i < len; i++)
            {
                ld.Add(keys[i], values[i]);
            }
            if (ld.Count != len)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", ld.Count, len));
            }

            ks = ld.Keys;
            if (ks.Count != len)
            {
                Assert.False(true, string.Format("Error, returned Keys.Count = {0}", ks.Count));
            }
            arr = Array.CreateInstance(typeof(Object), len);
            ks.CopyTo(arr, 0);
            for (int i = 0; i < len; i++)
            {
                ind = Array.IndexOf(arr, keys[i]);
                if (ind < 0)
                {
                    Assert.False(true, string.Format("Error, Keys doesn't contain \"{1}\" key. Search result: {2}", i, keys[i], ind));
                }
            }



            //
            //  get Keys on dictionary with identical values
            //
            //  [] get Keys for filled dictionary with identical value
            //

            ld.Clear();
//.........这里部分代码省略.........
开发者ID:noahfalk,项目名称:corefx,代码行数:101,代码来源:GetKeysTests.cs

示例7: Test01


//.........这里部分代码省略.........
            }

            // will return just removed item
            DictionaryEntry de2 = en.Entry;
            if (!de.Equals(de2))
            {
                Assert.False(true, string.Format("Error, Entry returned different value after modification"));
            }

            // will return just removed item
            Object k2 = en.Key;
            if (!k.Equals(k2))
            {
                Assert.False(true, string.Format("Error, Key returned different value after modification"));
            }

            // will return just removed item
            Object v2 = en.Value;
            if (!v.Equals(v2))
            {
                Assert.False(true, string.Format("Error, Value returned different value after modification"));
            }

            // exception expected
            Assert.Throws<InvalidOperationException>(() => { res = en.MoveNext(); });

            // exception expected
            Assert.Throws<InvalidOperationException>(() => { en.Reset(); });


            //
            //   [] Modify dictionary after enumerated beyond the end
            //
            ld.Clear();
            for (int i = 0; i < values.Length; i++)
            {
                ld.Add(keys[i], values[i]);
            }

            en = ld.GetEnumerator();
            for (int i = 0; i < ld.Count; i++)
            {
                en.MoveNext();
            }
            curr = (DictionaryEntry)en.Current;
            de = en.Entry;
            k = en.Key;
            v = en.Value;

            cnt = ld.Count;
            ld.Remove(keys[0]);
            if (ld.Count != cnt - 1)
            {
                Assert.False(true, string.Format("Error, didn't remove item with 0th key"));
            }

            // will return just removed item
            DictionaryEntry curr3 = (DictionaryEntry)en.Current;
            if (!curr.Equals(curr3))
            {
                Assert.False(true, string.Format("Error, current returned different value after modification"));
            }

            // will return just removed item
            de2 = en.Entry;
            if (!de.Equals(de2))
开发者ID:noahfalk,项目名称:corefx,代码行数:67,代码来源:GetEnumeratorTests.cs

示例8: Test01

        public void Test01()
        {
            IntlStrings intl;
            ListDictionary ld;

            // 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"
            };

            int cnt = 0;            // Count

            // initialize IntStrings
            intl = new IntlStrings();


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

            ld = new ListDictionary();
            cnt = ld.Count;
            if (cnt != 0)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1} after default ctor", ld.Count, 0));
            }

            //  [] Clear() on empty dictionary
            //
            ld.Clear();
            cnt = ld.Count;
            if (cnt != 0)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1} after Clear()", ld.Count, 0));
            }

            cnt = ld.Keys.Count;
            if (cnt != 0)
            {
                Assert.False(true, string.Format("Error, Keys.Count is {0} instead of {1} after Clear()", cnt, 0));
            }
            cnt = ld.Values.Count;
            if (cnt != 0)
            {
                Assert.False(true, string.Format("Error, Values.Count is {0} instead of {1} after Clear()", cnt, 0));
            }


            //  [] Add simple strings and Clear()
            //
            cnt = ld.Count;
            for (int i = 0; i < values.Length; i++)
            {
                ld.Add(keys[i], values[i]);
            }
            if (ld.Count != values.Length)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", ld.Count, values.Length));
            }

            ld.Clear();
            cnt = ld.Count;
            if (cnt != 0)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1} after Clear()", ld.Count, 0));
            }

            cnt = ld.Keys.Count;
            if (cnt != 0)
            {
                Assert.False(true, string.Format("Error, Keys.Count is {0} instead of {1} after Clear()", cnt, 0));
            }
            cnt = ld.Values.Count;
            if (cnt != 0)
//.........这里部分代码省略.........
开发者ID:noahfalk,项目名称:corefx,代码行数:101,代码来源:ClearTests.cs

示例9: Test01

        public void Test01()
        {
            ListDictionary ld;

            // 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"
            };

            int cnt = 0;            // Count

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

            ld = new ListDictionary();
            cnt = ld.Count;
            if (cnt != 0)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1} after default ctor", ld.Count, 0));
            }

            //   [] Clear() empty dictionary and get Count
            //
            ld.Clear();
            cnt = ld.Count;
            if (cnt != 0)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1} after Clear()", ld.Count, 0));
            }

            cnt = ld.Keys.Count;
            if (cnt != 0)
            {
                Assert.False(true, string.Format("Error, Keys.Count is {0} instead of {1} after Clear()", cnt, 0));
            }
            cnt = ld.Values.Count;
            if (cnt != 0)
            {
                Assert.False(true, string.Format("Error, Values.Count is {0} instead of {1} after Clear()", cnt, 0));
            }


            //  [] Add simple strings - Count -  Clear() - Count
            //
            cnt = ld.Count;
            for (int i = 0; i < values.Length; i++)
            {
                ld.Add(keys[i], values[i]);
            }
            if (ld.Count != values.Length)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", ld.Count, values.Length));
            }

            ld.Clear();
            cnt = ld.Count;
            if (cnt != 0)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1} after Clear()", ld.Count, 0));
            }

            cnt = ld.Keys.Count;
            if (cnt != 0)
            {
                Assert.False(true, string.Format("Error, Keys.Count is {0} instead of {1} after Clear()", cnt, 0));
            }
            cnt = ld.Values.Count;
            if (cnt != 0)
            {
                Assert.False(true, string.Format("Error, Values.Count is {0} instead of {1} after Clear()", cnt, 0));
            }
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:99,代码来源:GetCountTests.cs

示例10: Test01

        public void Test01()
        {
            ListDictionary ld;

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

            ld = new ListDictionary();


            if (ld == null)
            {
                Assert.False(true, string.Format("Error, dictionary is null after default ctor"));
            }

            if (ld.Count != 0)
            {
                Assert.False(true, string.Format("Error, Count = {0} after default ctor", ld.Count));
            }

            if (ld["key"] != null)
            {
                Assert.False(true, string.Format("Error, Item(some_key) returned non-null after default ctor"));
            }

            System.Collections.ICollection keys = ld.Keys;
            if (keys.Count != 0)
            {
                Assert.False(true, string.Format("Error, Keys contains {0} keys after default ctor", keys.Count));
            }

            System.Collections.ICollection values = ld.Values;
            if (values.Count != 0)
            {
                Assert.False(true, string.Format("Error, Values contains {0} items after default ctor", values.Count));
            }

            //
            // [] Add(string, string)
            //
            ld.Add("Name", "Value");
            if (ld.Count != 1)
            {
                Assert.False(true, string.Format("Error, Count returned {0} instead of 1", ld.Count));
            }
            if (String.Compare(ld["Name"].ToString(), "Value") != 0)
            {
                Assert.False(true, string.Format("Error, Item() returned unexpected value"));
            }

            //
            // [] Clear()
            //
            ld.Clear();
            if (ld.Count != 0)
            {
                Assert.False(true, string.Format("Error, Count returned {0} instead of 0 after Clear()", ld.Count));
            }
            if (ld["Name"] != null)
            {
                Assert.False(true, string.Format("Error, Item() returned non-null value after Clear()"));
            }

            //
            // [] elements not overriding Equals()
            //
            ld.Clear();
            Hashtable lbl = new Hashtable();
            Hashtable lbl1 = new Hashtable();
            ArrayList b = new ArrayList();
            ArrayList b1 = new ArrayList();
            ld.Add(lbl, b);
            ld.Add(lbl1, b1);
            if (ld.Count != 2)
            {
                Assert.False(true, string.Format("Error, Count returned {0} instead of 2", ld.Count));
            }
            if (!ld.Contains(lbl))
            {
                Assert.False(true, string.Format("Error, doesn't contain 1st special item"));
            }
            if (!ld.Contains(lbl1))
            {
                Assert.False(true, string.Format("Error, doesn't contain 2nd special item"));
            }
            if (ld.Values.Count != 2)
            {
                Assert.False(true, string.Format("Error, Values.Count returned {0} instead of 2", ld.Values.Count));
            }

            ld.Remove(lbl1);
            if (ld.Count != 1)
            {
                Assert.False(true, string.Format("Error, failed to remove item"));
            }
            if (ld.Contains(lbl1))
            {
                Assert.False(true, string.Format("Error, failed to remove special item"));
            }
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:100,代码来源:CtorTests.cs

示例11: Test01


//.........这里部分代码省略.........
            for (int i = 0; i < len; i++)
            {
                if (!ld.Contains(keys[i]))
                {
                    Assert.False(true, string.Format("Error, doesn't contain \"{1}\"", i, keys[i]));
                }
            }


            //
            // Intl strings
            // [] Intl strings and Contains()
            //

            string[] intlValues = new string[len * 2];

            // fill array with unique strings
            //
            for (int i = 0; i < len * 2; i++)
            {
                string val = intl.GetRandomString(MAX_LEN);
                while (Array.IndexOf(intlValues, val) != -1)
                    val = intl.GetRandomString(MAX_LEN);
                intlValues[i] = val;
            }

            Boolean caseInsensitive = false;
            for (int i = 0; i < len * 2; i++)
            {
                if (intlValues[i].Length != 0 && intlValues[i].ToLower() == intlValues[i].ToUpper())
                    caseInsensitive = true;
            }

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

            for (int i = 0; i < len; i++)
            {
                //
                if (!ld.Contains(intlValues[i + len]))
                {
                    Assert.False(true, string.Format("Error, doesn't contain \"{1}\"", i, intlValues[i + len]));
                }
            }


            //
            // [] Case sensitivity
            // by default ListDictionary is case-sensitive
            //

            string[] intlValuesLower = new string[len * 2];

            // fill array with unique strings
            //
            for (int i = 0; i < len * 2; i++)
            {
                intlValues[i] = intlValues[i].ToUpper();
            }
开发者ID:noahfalk,项目名称:corefx,代码行数:67,代码来源:ContainsObjTests.cs

示例12: Performance

		public void Performance()
		{
			// set the hashtable and SequencedHashMap to be the 
			IDictionary hashtable;
			IDictionary sequenced;
			IDictionary list;

			int numOfRuns = 4;

			int numOfEntries = Int16.MaxValue;

			long hashStart;
			long[] hashPopulateTicks = new long[numOfRuns];
			long[] hashItemTicks = new long[numOfRuns];

			long seqStart;
			long[] seqPopulateTicks = new long[numOfRuns];
			long[] seqItemTicks = new long[numOfRuns];

			long listStart;
			long[] listPopulateTicks = new long[numOfRuns];
			long[] listItemTicks = new long[numOfRuns];

			for (int runIndex = 0; runIndex < numOfRuns; runIndex++)
			{
				object key;
				object value;
				hashtable = new Hashtable();
				sequenced = new SequencedHashMap();
				list = new ListDictionary();

				hashStart = DateTime.Now.Ticks;

				for (int i = 0; i < numOfEntries; i++)
				{
					hashtable.Add("test" + i, new object());
				}

				hashPopulateTicks[runIndex] = DateTime.Now.Ticks - hashStart;

				hashStart = DateTime.Now.Ticks;
				for (int i = 0; i < numOfEntries; i++)
				{
					key = "test" + i;
					value = hashtable[key];
				}

				hashItemTicks[runIndex] = DateTime.Now.Ticks - hashStart;

				hashtable.Clear();

				seqStart = DateTime.Now.Ticks;

				for (int i = 0; i < numOfEntries; i++)
				{
					sequenced.Add("test" + i, new object());
				}

				seqPopulateTicks[runIndex] = DateTime.Now.Ticks - seqStart;

				seqStart = DateTime.Now.Ticks;
				for (int i = 0; i < numOfEntries; i++)
				{
					key = "test" + i;
					value = sequenced[key];
				}

				seqItemTicks[runIndex] = DateTime.Now.Ticks - seqStart;

				sequenced.Clear();

				listStart = DateTime.Now.Ticks;

				for (int i = 0; i < numOfEntries; i++)
				{
					list.Add("test" + i, new object());
				}

				listPopulateTicks[runIndex] = DateTime.Now.Ticks - listStart;

				listStart = DateTime.Now.Ticks;
				for (int i = 0; i < numOfEntries; i++)
				{
					key = "test" + i;
					value = list[key];
				}

				listItemTicks[runIndex] = DateTime.Now.Ticks - listStart;


				list.Clear();
			}

			for (int runIndex = 0; runIndex < numOfRuns; runIndex++)
			{
				decimal seqPopulateOverhead = ((decimal) seqPopulateTicks[runIndex] / (decimal) hashPopulateTicks[runIndex]);
				decimal seqItemOverhead = ((decimal) seqItemTicks[runIndex] / (decimal) hashItemTicks[runIndex]);

				string errMessage = "SequenceHashMap vs Hashtable:";
				errMessage += "\n POPULATE:";
//.........这里部分代码省略.........
开发者ID:hoangduc007,项目名称:nhibernate-core,代码行数:101,代码来源:SequencedHashMapFixture.cs

示例13: Test01


//.........这里部分代码省略.........

                ld.Add(intlValues[i + len], intlValues[i]);
                if (ld.Count != cnt + 1)
                {
                    Assert.False(true, string.Format("Error, count is {1} instead of {2}", i, ld.Count, cnt + 1));
                }

                //  access the item
                //
                if (String.Compare(ld[intlValues[i + len]].ToString(), intlValues[i]) != 0)
                {
                    Assert.False(true, string.Format("Error, returned item \"{1}\" instead of \"{2}\"", i, ld[intlValues[i + len]], intlValues[i]));
                }
            }

            //
            // [] Case sensitivity
            // Casing doesn't change ( keys are not converted to lower!)
            //
            string[] intlValuesLower = new string[len * 2];

            // fill array with unique strings
            //
            for (int i = 0; i < len * 2; i++)
            {
                intlValues[i] = intlValues[i].ToUpper();
            }

            for (int i = 0; i < len * 2; i++)
            {
                intlValuesLower[i] = intlValues[i].ToLower();
            }

            ld.Clear();
            //
            // will use first half of array as values and second half as keys
            //
            for (int i = 0; i < len; i++)
            {
                cnt = ld.Count;

                ld.Add(intlValues[i + len], intlValues[i]);
                if (ld.Count != cnt + 1)
                {
                    Assert.False(true, string.Format("Error, count is {1} instead of {2}", i, ld.Count, cnt + 1));
                }

                //  access the item
                //
                if (ld[intlValues[i + len]] == null)
                {
                    Assert.False(true, string.Format("Error, returned null", i));
                }
                else
                {
                    if (!ld[intlValues[i + len]].Equals(intlValues[i]))
                    {
                        Assert.False(true, string.Format("Error, returned item \"{1}\" instead of \"{2}\"", i, ld[intlValues[i + len]], intlValues[i]));
                    }
                }

                // verify that dictionary doesn't contains lowercase item
                //
                if (!caseInsensitive && ld[intlValuesLower[i + len]] != null)
                {
                    Assert.False(true, string.Format("Error, returned non-null", i));
开发者ID:noahfalk,项目名称:corefx,代码行数:67,代码来源:AddObjObjTests.cs


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