本文整理汇总了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"));
}
示例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);
//.........这里部分代码省略.........
示例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++;
示例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";