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


C# ListDictionary.Remove方法代码示例

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


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

示例1: AddRemoveAddItemsDoesntChangeItemsOrder

            public void AddRemoveAddItemsDoesntChangeItemsOrder(int itemsToAddCount, int itemsToRemoveCount)
            {
                var dict = new ListDictionary<string, int>();

                for (var i = 0; i < itemsToAddCount; i++)
                {
                    var key = i.ToString();
                    dict[key] = 0;
                }

                for (var i = 0; i < itemsToRemoveCount; i++)
                {
                    var key = (itemsToAddCount - itemsToRemoveCount + i).ToString();
                    dict.Remove(key);
                }

                for (var i = itemsToAddCount - itemsToRemoveCount; i < itemsToAddCount; i++)
                {
                    var key = i.ToString();
                    dict[key] = 0;
                }

                var keyValuePairs = dict.ToList();
                for (var i = 0; i < itemsToAddCount; i++)
                {
                    Assert.AreEqual(i.ToString(), keyValuePairs[i].Key);
                }
            }
开发者ID:jensweller,项目名称:Catel,代码行数:28,代码来源:ListDictionaryFacts.cs

示例2: KeyCollection_GetEnumerator_ModifiedCollectionTest

 public static void KeyCollection_GetEnumerator_ModifiedCollectionTest(ListDictionary ld, KeyValuePair<string, string>[] data)
 {
     IEnumerator enumerator = ld.Keys.GetEnumerator();
     Assert.NotNull(enumerator);
     if (data.Length > 0)
     {
         Assert.True(enumerator.MoveNext());
         object current = enumerator.Current;
         ld.Remove("key");
         Assert.Equal(current, enumerator.Current);
         Assert.Throws<InvalidOperationException>(() => enumerator.MoveNext());
         Assert.Throws<InvalidOperationException>(() => enumerator.Reset());
     }
     else
     {
         ld.Add("newKey", "newValue");
         Assert.Throws<InvalidOperationException>(() => enumerator.MoveNext());
     }
 }
开发者ID:SGuyGe,项目名称:corefx,代码行数:19,代码来源:ListDictionaryTests.cs

示例3: Remove_NotPresentTest

 public static void Remove_NotPresentTest(ListDictionary ld, KeyValuePair<string, string>[] data)
 {
     ld.Remove("notpresent");
     Assert.Equal(data.Length, ld.Count);
     Assert.Throws<ArgumentNullException>("key", () => ld.Remove(null));
 }
开发者ID:SGuyGe,项目名称:corefx,代码行数:6,代码来源:ListDictionaryTests.cs

示例4: RemoveTest

 public static void RemoveTest(ListDictionary ld, KeyValuePair<string, string>[] data)
 {
     Assert.All(data, element =>
     {
         Assert.True(ld.Contains(element.Key));
         ld.Remove(element.Key);
         Assert.False(ld.Contains(element.Key));
     });
     Assert.Equal(0, ld.Count);
 }
开发者ID:SGuyGe,项目名称:corefx,代码行数:10,代码来源:ListDictionaryTests.cs

示例5: runTest


//.........这里部分代码省略.........
         {
             iCountErrors++;
             Console.WriteLine("Err_0004a, count is {0} instead of {1}", ld.Count, len);
         }
         ks = ld.Keys;
         if (ks.Count != len) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0004b, returned Keys.Count = {0}", ks.Count);
         }
         arr = Array.CreateInstance(typeof(Object), len);
         ks.CopyTo(arr, 0);
         for (int i = 0; i < arr.Length; i++) 
         {
             iCountTestcases++;
             ind = Array.IndexOf(arr, intlValues[i+len]);
             if (ind < 0) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0004c_{0}, Keys doesn't contain \"{1}\" key", i, intlValues[i+len]);
             } 
         }
         Console.WriteLine("5. Change dictinary");
         strLoc = "Loc_005oo"; 
         iCountTestcases++;
         ld.Clear();
         for (int i = 0; i < len; i++) 
         {
             ld.Add(keys[i], values[i]);
         }
         if (ld.Count != len) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0005a, count is {0} instead of {1}", ld.Count, len);
         } 
         ks = ld.Keys;
         if (ks.Count != len) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0005a, returned Keys.Count = {0}", ks.Count);
         }
         Console.WriteLine("     - remove element from the dictionary");
         ld.Remove(keys[0]);
         if (ld.Count != len-1) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0005b, didn't remove element");
         } 
         if (ks.Count != len-1) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0005c, Keys were not updated after removal");
         }
         iCountTestcases++;
         arr = Array.CreateInstance(typeof(Object), ld.Count);
         ks.CopyTo(arr, 0);
         ind = Array.IndexOf(arr, keys[0]);
         if (ind >= 0) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0005d, Keys still contains removed key " + ind);
         } 
         Console.WriteLine("     - add element to the dictionary");
         ld.Add(keys[0], "new item");
         if (ld.Count != len) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0005e, didn't add element");
         } 
         if (ks.Count != len) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0005f, Keys were not updated after addition");
         }
         iCountTestcases++;
         arr = Array.CreateInstance(typeof(Object), ld.Count);
         ks.CopyTo(arr, 0);
         ind = Array.IndexOf(arr, keys[0]);
         if (ind < 0) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0005g, Keys doesn't contain added key ");
         } 
     } 
     catch (Exception exc_general ) 
     {
         ++iCountErrors;
         Console.WriteLine (s_strTFAbbrev + " : Error Err_general!  strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString());
     }
     if ( iCountErrors == 0 )
     {
         Console.WriteLine( "Pass.   "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
         return true;
     }
     else
     {
         Console.WriteLine("Fail!   "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
         return false;
     }
 }
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co8696get_keys.cs

示例6: runTest

 public virtual bool runTest()
 {
     Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
     int iCountErrors = 0;
     int iCountTestcases = 0;
     IntlStrings intl;
     String strLoc = "Loc_000oo";
     ListDictionary ld; 
     string [] values = 
     {
         "",
         " ",
         "a",
         "aA",
         "text",
         "     SPaces",
         "1",
         "$%^#",
         "2222222222222222222222222",
         System.DateTime.Today.ToString(),
         Int32.MaxValue.ToString()
     };
     string [] keys = 
     {
         "zero",
         "oNe",
         " ",
         "",
         "aa",
         "1",
         System.DateTime.Today.ToString(),
         "$%^#",
         Int32.MaxValue.ToString(),
         "     spaces",
         "2222222222222222222222222"
     };
     int cnt = 0;            
     try
     {
         intl = new IntlStrings(); 
         Console.WriteLine("--- create dictionary ---");
         strLoc = "Loc_001oo"; 
         iCountTestcases++;
         ld = new ListDictionary();
         Console.WriteLine("1. Remove() on empty dictionary");
         iCountTestcases++;
         cnt = ld.Count;
         Console.WriteLine("     - Remove(null)");
         try 
         {
             ld.Remove(null);
             iCountErrors++;
             Console.WriteLine("Err_0001a, no exception");
         }
         catch (ArgumentNullException ex) 
         {
             Console.WriteLine(" Expected exception: {0}", ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001b, unexpected exception: {0}", e.ToString());
         }
         iCountTestcases++;
         cnt = ld.Count;
         Console.WriteLine("     - Remove(some_string)");
         ld.Remove("some_string");
         if (ld.Count != cnt) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001c, changed dictionary after Remove(some_string)");
         }
         Console.WriteLine("2. add simple strings, Remove(Object)");
         strLoc = "Loc_002oo"; 
         iCountTestcases++;
         cnt = ld.Count;
         int len = values.Length;
         for (int i = 0; i < len; i++) 
         {
             ld.Add(keys[i], values[i]);
         }
         if (ld.Count != len) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002a, count is {0} instead of {1}", ld.Count, values.Length);
         } 
         for (int i = 0; i < len; i++) 
         {
             cnt = ld.Count;
             iCountTestcases++;
             ld.Remove(keys[i]);
             if (ld.Count != cnt - 1) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002_{0}b, returned: failed to remove item", i);
             } 
             iCountTestcases++;
             if ( ld.Contains(keys[i]) ) 
             {
                 iCountErrors++;
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co8689remove_obj.cs

示例7: RemovedAllItems

            public void RemovedAllItems(int itemsCount)
            {
                var listDictionary = new ListDictionary<string, int>();

                for (int i = 0; i < itemsCount; i++)
                {
                    listDictionary[i.ToString()] = i;
                }

                for (int i = 0; i < itemsCount; i++)
                {
                    listDictionary.Remove(i.ToString());
                }

                Assert.AreEqual(0, listDictionary.Count);
            }
开发者ID:matthijskoopman,项目名称:Catel,代码行数:16,代码来源:ListDictionaryFacts.cs


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