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


C# StringDictionary.Remove方法代码示例

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


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

示例1: Remove_DuplicateValues

        public void Remove_DuplicateValues()
        {
            StringDictionary stringDictionary = new StringDictionary();
            stringDictionary.Add("key1", "value");
            stringDictionary.Add("key2", "value");

            stringDictionary.Remove("key1");
            Assert.Equal(1, stringDictionary.Count);
            Assert.False(stringDictionary.ContainsKey("key1"));
            Assert.True(stringDictionary.ContainsValue("value"));

            stringDictionary.Remove("key2");
            Assert.Equal(0, stringDictionary.Count);
            Assert.False(stringDictionary.ContainsKey("key2"));
            Assert.False(stringDictionary.ContainsValue("value"));
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:16,代码来源:StringDictionary.RemoveTests.cs

示例2: 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";
     StringDictionary sd; 
     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++;
         sd = new StringDictionary();
         Console.WriteLine("1. Remove() from empty dictionary");
         iCountTestcases++;
         if (sd.Count > 0)
             sd.Clear();
         for (int i = 0; i < keys.Length; i++) 
         {
             sd.Remove(keys[0]);
         }
         Console.WriteLine("2. Remove() on filled dictionary");  
         strLoc = "Loc_002oo"; 
         int len = values.Length;
         iCountTestcases++;
         sd.Clear();
         for (int i = 0; i < len; i++) 
         {
             sd.Add(keys[i], values[i]);
         }
         if (sd.Count != len) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002a, count is {0} instead of {1}", sd.Count, len);
         } 
         for (int i = 0; i < len; i++) 
         {
             iCountTestcases++;
             cnt = sd.Count;
             sd.Remove(keys[i]);
             if (sd.Count != cnt - 1) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002b_{0}, didn't remove element with {0} key", i);
             } 
             iCountTestcases++;
             if ( sd.ContainsValue(values[i]) ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002c_{0}, removed wrong value", i);
             } 
             iCountTestcases++;
             if ( sd.ContainsKey(keys[i]) ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002d_{0}, removed wrong value", i);
             } 
         }
         Console.WriteLine("3. Remove() on dictionary with duplicate values ");
         strLoc = "Loc_003oo"; 
         iCountTestcases++;
         sd.Clear();
         string intlStr = intl.GetString(MAX_LEN, true, true, true);
         sd.Add("keykey1", intlStr);        
         for (int i = 0; i < len; i++) 
         {
             sd.Add(keys[i], values[i]);
         }
         sd.Add("keykey2", intlStr);        
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co8761remove_str.cs

示例3: runTest


//.........这里部分代码省略.........
         }
         arr = Array.CreateInstance(typeof(string), len);
         vs.CopyTo(arr, 0);
         for (int i = 0; i < arr.Length; i++) 
         {
             iCountTestcases++;
             ind = Array.IndexOf(arr, intlValues[i]);
             if (ind < 0) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0004c_{0}, Values doesn't contain \"{1}\" value", i, intlValues[i]);
             } 
         }
         Console.WriteLine("5. Change dictinary and verify case sensitivity");
         strLoc = "Loc_005oo"; 
         iCountTestcases++;
         sd.Clear();
         for (int i = 0; i < len; i++) 
         {
             sd.Add(keys[i], values[i]);
         }
         if (sd.Count != len) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0005a, count is {0} instead of {1}", sd.Count, len);
         } 
         vs = sd.Values;
         if (vs.Count != len) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0005a, returned Values.Count = {0}", vs.Count);
         }
         Console.WriteLine("     - remove element from the dictionary");
         sd.Remove(keys[0]);
         if (sd.Count != len-1) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0005b, didn't remove element");
         } 
         if (vs.Count != len-1) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0005c, Values were not updated after removal");
         }
         iCountTestcases++;
         arr = Array.CreateInstance(typeof(string), sd.Count);
         vs.CopyTo(arr, 0);
         ind = Array.IndexOf(arr, values[0]);
         if (ind >= 0) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0005d, Values still contains removed value " + ind);
         } 
         Console.WriteLine("     - add element to the dictionary");
         sd.Add(keys[0], "new item");
         if (sd.Count != len) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0005e, didn't add element");
         } 
         if (vs.Count != len) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0005f, Values were not updated after addition");
         }
         iCountTestcases++;
开发者ID:ArildF,项目名称:masters,代码行数:67,代码来源:co8767get_values.cs

示例4: runTest


//.........这里部分代码省略.........
         }
         catch (InvalidOperationException ex) 
         {
             Console.WriteLine("  expected exception: " + ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002k, unexpected exception: {0}", e.ToString());
         }
         Console.WriteLine("3. Enumerator and modified dictionary");
         strLoc = "Loc_003oo"; 
         iCountTestcases++;
         if (sd.Count < 1) 
         {
             for (int i = 0; i < values.Length; i++) 
             {
                 sd.Add(keys[i], values[i]);
             }
         }
         iCountTestcases++;
         en = sd.GetEnumerator();
         Console.WriteLine("     - MoveNext");
         res = en.MoveNext();
         if (!res) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0003a, MoveNext returned false");
         }
         Console.WriteLine("     - modify collection");
         curr = (DictionaryEntry)en.Current;
         int cnt = sd.Count;
         iCountTestcases++;
         sd.Remove(keys[0]);
         if ( sd.Count != cnt - 1 ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0003b, didn't remove item with 0th key");
         }
         Console.WriteLine("     - get Current");
         iCountTestcases++;
         DictionaryEntry curr2 = (DictionaryEntry)en.Current;
         if (! curr.Equals(curr2) ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0003c, current returned different value after midification");
         }
         Console.WriteLine("     - call MoveNext");
         iCountTestcases++;
         try 
         {
             res = en.MoveNext();
             iCountErrors++;
             Console.WriteLine("Err_0003d, no exception");
         }
         catch (InvalidOperationException ex) 
         {
             Console.WriteLine("  expected exception: " + ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0003e, unexpected exception: {0}", e.ToString());
         }
         Console.WriteLine("4. Modify dictionary after enumerated beyond the end");
         strLoc = "Loc_004oo"; 
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:67,代码来源:co8760getenumerator.cs


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