本文整理汇总了C#中System.Collections.Specialized.StringDictionary.ContainsValue方法的典型用法代码示例。如果您正苦于以下问题:C# StringDictionary.ContainsValue方法的具体用法?C# StringDictionary.ContainsValue怎么用?C# StringDictionary.ContainsValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Specialized.StringDictionary
的用法示例。
在下文中一共展示了StringDictionary.ContainsValue方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: This_Empty
public void This_Empty ()
{
StringDictionary sd = new StringDictionary ();
sd[String.Empty] = null;
Assert.IsNull (sd[String.Empty], "this[String.Empty]");
Assert.AreEqual (1, sd.Count, "Count-1");
Assert.IsTrue (sd.ContainsKey (String.Empty), "ContainsKey");
Assert.IsTrue (sd.ContainsValue (null), "ContainsValue");
}
示例2: Main
public static void Main()
{
// Creates and initializes a new StringDictionary.
StringDictionary myCol = new StringDictionary();
myCol.Add("red", "rojo");
myCol.Add("green", "verde");
myCol.Add("blue", "azul");
Console.WriteLine("Count: {0}", myCol.Count);
// Display the contents of the collection using foreach. This is the preferred method.
Console.WriteLine("Displays the elements using foreach:");
PrintKeysAndValues1(myCol);
// Display the contents of the collection using the enumerator.
Console.WriteLine("Displays the elements using the IEnumerator:");
PrintKeysAndValues2(myCol);
// Display the contents of the collection using the Keys, Values, Count, and Item properties.
Console.WriteLine("Displays the elements using the Keys, Values, Count, and Item properties:");
PrintKeysAndValues3(myCol);
// Copies the StringDictionary to an array with DictionaryEntry elements.
DictionaryEntry[] myArr = new DictionaryEntry[myCol.Count];
myCol.CopyTo(myArr, 0);
// Displays the values in the array.
Console.WriteLine("Displays the elements in the array:");
Console.WriteLine(" KEY VALUE");
for (int i = 0; i < myArr.Length; i++)
Console.WriteLine(" {0,-10} {1}", myArr[i].Key, myArr[i].Value);
Console.WriteLine();
// Searches for a value.
if (myCol.ContainsValue("amarillo"))
Console.WriteLine("The collection contains the value \"amarillo\".");
else
Console.WriteLine("The collection does not contain the value \"amarillo\".");
Console.WriteLine();
// Searches for a key and deletes it.
if (myCol.ContainsKey("green"))
myCol.Remove("green");
Console.WriteLine("The collection contains the following elements after removing \"green\":");
PrintKeysAndValues1(myCol);
// Clears the entire collection.
myCol.Clear();
Console.WriteLine("The collection contains the following elements after it is cleared:");
PrintKeysAndValues1(myCol);
}
示例3: Empty
public void Empty ()
{
StringDictionary sd = new StringDictionary ();
Assert.AreEqual (0, sd.Count, "Count");
Assert.IsFalse (sd.IsSynchronized, "IsSynchronized");
Assert.AreEqual (0, sd.Keys.Count, "Keys");
Assert.AreEqual (0, sd.Values.Count, "Values");
Assert.IsNotNull (sd.SyncRoot, "SyncRoot");
Assert.IsFalse (sd.ContainsKey ("a"), "ContainsKey");
Assert.IsFalse (sd.ContainsValue ("1"), "ContainsValue");
sd.CopyTo (new DictionaryEntry[0], 0);
Assert.IsNotNull (sd.GetEnumerator (), "GetEnumerator");
sd.Remove ("a"); // doesn't exists
sd.Clear ();
}
示例4: Test01
public void Test01()
{
StringDictionary sd;
// [] StringDictionary is constructed as expected
//-----------------------------------------------------------------
sd = new StringDictionary();
// [] Compare to null
//
if (sd == null)
{
Assert.False(true, string.Format("Error, collection is null after default ctor"));
}
// [] check Count
//
if (sd.Count != 0)
{
Assert.False(true, string.Format("Error, Count = {0} after default ctor", sd.Count));
}
// [] check other properties
//
if (sd.ContainsValue("string"))
{
Assert.False(true, string.Format("Error, ContainsValue() returned true after default ctor"));
}
if (sd.ContainsKey("string"))
{
Assert.False(true, string.Format("Error, ContainsKey() returned true after default ctor"));
}
//
// IsSynchronized = false by default
//
if (sd.IsSynchronized)
{
Assert.False(true, string.Format("Error, IsSynchronized returned {0}", sd.IsSynchronized));
}
//
// [] Add item and verify
//
sd.Add("key", "value");
if (sd.Count != 1)
{
Assert.False(true, string.Format("Error, Count returned {0}", sd.Count));
}
if (!sd.ContainsKey("key"))
{
Assert.False(true, string.Format("Error, ContainsKey() returned false"));
}
if (!sd.ContainsValue("value"))
{
Assert.False(true, string.Format("Error, ContainsValue() returned false"));
}
}
示例5: Test01
public void Test01()
{
StringDictionary sd;
IEnumerator en;
DictionaryEntry curr; // Enumerator.Current value
// 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"
};
// [] StringDictionary GetEnumerator()
//-----------------------------------------------------------------
sd = new StringDictionary();
// [] Enumerator for empty dictionary
//
en = sd.GetEnumerator();
string type = en.GetType().ToString();
if (type.IndexOf("Enumerator", 0) == 0)
{
Assert.False(true, string.Format("Error, type is not Enumerator"));
}
//
// MoveNext should return false
//
bool res = en.MoveNext();
if (res)
{
Assert.False(true, string.Format("Error, MoveNext returned true"));
}
//
// Attempt to get Current should result in exception
//
Assert.Throws<InvalidOperationException>(() => { curr = (DictionaryEntry)en.Current; });
//
// Filled collection
// [] Enumerator for filled dictionary
//
for (int i = 0; i < values.Length; i++)
{
sd.Add(keys[i], values[i]);
}
en = sd.GetEnumerator();
type = en.GetType().ToString();
if (type.IndexOf("Enumerator", 0) == 0)
{
Assert.False(true, string.Format("Error, type is not Enumerator"));
}
//
// MoveNext should return true
//
for (int i = 0; i < sd.Count; i++)
{
res = en.MoveNext();
if (!res)
{
Assert.False(true, string.Format("Error, MoveNext returned false", i));
}
curr = (DictionaryEntry)en.Current;
//
//enumerator enumerates in different than added order
// so we'll check Contains
//
if (!sd.ContainsValue(curr.Value.ToString()))
{
//.........这里部分代码省略.........
示例6: Test01
public void Test01()
{
IntlStrings intl;
StringDictionary sd;
// 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;
// initialize IntStrings
intl = new IntlStrings();
// [] StringDictionary is constructed as expected
//-----------------------------------------------------------------
sd = new StringDictionary();
// [] Remove() from empty dictionary
//
if (sd.Count > 0)
sd.Clear();
for (int i = 0; i < keys.Length; i++)
{
sd.Remove(keys[0]);
}
// [] Remove() from filled dictionary
//
int len = values.Length;
sd.Clear();
for (int i = 0; i < len; i++)
{
sd.Add(keys[i], values[i]);
}
if (sd.Count != len)
{
Assert.False(true, string.Format("Error, count is {0} instead of {1}", sd.Count, len));
}
for (int i = 0; i < len; i++)
{
cnt = sd.Count;
sd.Remove(keys[i]);
if (sd.Count != cnt - 1)
{
Assert.False(true, string.Format("Error, didn't remove element with {0} key", i));
}
// verify that indeed element with given key was removed
if (sd.ContainsValue(values[i]))
{
Assert.False(true, string.Format("Error, removed wrong value", i));
}
if (sd.ContainsKey(keys[i]))
{
Assert.False(true, string.Format("Error, removed wrong value", i));
}
}
//
// [] Remove() on dictionary with identical values
//
sd.Clear();
string intlStr = intl.GetRandomString(MAX_LEN);
sd.Add("keykey1", intlStr); // 1st duplicate
for (int i = 0; i < len; i++)
//.........这里部分代码省略.........
示例7: SomeElements
public void SomeElements ()
{
StringDictionary sd = new StringDictionary ();
for (int i = 0; i < 10; i++)
sd.Add (i.ToString (), (i * 10).ToString ());
Assert.AreEqual ("10", sd["1"], "this[1]");
Assert.AreEqual (10, sd.Count, "Count-10");
Assert.AreEqual (10, sd.Keys.Count, "Keys");
Assert.AreEqual (10, sd.Values.Count, "Values");
Assert.IsTrue (sd.ContainsKey ("2"), "ContainsKey");
Assert.IsTrue (sd.ContainsValue ("20"), "ContainsValue");
DictionaryEntry[] array = new DictionaryEntry[10];
sd.CopyTo (array, 0);
sd.Remove ("1");
Assert.AreEqual (9, sd.Count, "Count-9");
sd.Clear ();
Assert.AreEqual (0, sd.Count, "Count-0");
}
示例8: Test01
public void Test01()
{
IntlStrings intl;
StringDictionary sd;
string ind;
// 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();
// [] StringDictionary is constructed as expected
//-----------------------------------------------------------------
sd = new StringDictionary();
// [] check for empty dictionary
//
for (int i = 0; i < values.Length; i++)
{
if (sd.ContainsKey(keys[i]))
{
Assert.False(true, string.Format("Error, returned true for empty dictionary", i));
}
}
// [] add simple strings and verify ContainsKey()
//
cnt = values.Length;
for (int i = 0; i < cnt; i++)
{
sd.Add(keys[i], values[i]);
}
if (sd.Count != cnt)
{
Assert.False(true, string.Format("Error, count is {0} instead of {1}", sd.Count, cnt));
}
for (int i = 0; i < cnt; i++)
{
// verify that collection contains all added items
//
if (!sd.ContainsValue(values[i]))
{
Assert.False(true, string.Format("Error, collection doesn't contain value \"{1}\"", i, values[i]));
}
if (!sd.ContainsKey(keys[i]))
{
Assert.False(true, string.Format("Error, collection doesn't contain key \"{1}\"", i, keys[i]));
}
}
//
// Intl strings
// [] add Intl strings and verify ContainsKey()
//
int len = values.Length;
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;
//.........这里部分代码省略.........
示例9: BindCountries
/// <summary>
/// Binds the country dropdown list with countries retrieved
/// from the .NET Framework.
/// </summary>
public void BindCountries()
{
var dic = new StringDictionary();
var col = new List<string>();
foreach (
var ri in CultureInfo.GetCultures(CultureTypes.SpecificCultures).Select(ci => new RegionInfo(ci.Name)))
{
if (!dic.ContainsKey(ri.EnglishName))
{
dic.Add(ri.EnglishName, ri.TwoLetterISORegionName.ToLowerInvariant());
}
if (!col.Contains(ri.EnglishName))
{
col.Add(ri.EnglishName);
}
}
// Add custom cultures
if (!dic.ContainsValue("bd"))
{
dic.Add("Bangladesh", "bd");
col.Add("Bangladesh");
}
col.Sort();
this.ddlCountry.Items.Add(new ListItem("[Not specified]", string.Empty));
foreach (var key in col)
{
this.ddlCountry.Items.Add(new ListItem(key, dic[key]));
}
if (this.ddlCountry.SelectedIndex == 0)
{
this.ddlCountry.SelectedValue = ResolveRegion().TwoLetterISORegionName.ToLowerInvariant();
this.SetFlagImageUrl();
}
}
示例10: Test01
public void Test01()
{
IntlStrings intl;
StringDictionary sd;
// 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
string ind; // key
// initialize IntStrings
intl = new IntlStrings();
// [] StringDictionary is constructed as expected
//-----------------------------------------------------------------
sd = new StringDictionary();
// [] Add() simple strings
//
for (int i = 0; i < values.Length; i++)
{
cnt = sd.Count;
sd.Add(keys[i], values[i]);
if (sd.Count != cnt + 1)
{
Assert.False(true, string.Format("Error, count is {1} instead of {2}", i, sd.Count, cnt + 1));
}
// verify that collection contains newly added item
//
if (!sd.ContainsValue(values[i]))
{
Assert.False(true, string.Format("Error, collection doesn't contain value of new item", i));
}
if (!sd.ContainsKey(keys[i]))
{
Assert.False(true, string.Format("Error, collection doesn't contain key of new item", i));
}
// access the item
//
if (String.Compare(sd[keys[i]], values[i]) != 0)
{
Assert.False(true, string.Format("Error, returned item \"{1}\" instead of \"{2}\"", i, sd[keys[i]], values[i]));
}
}
//
// Intl strings
// [] Add() Intl strings
//
int len = values.Length;
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].ToLowerInvariant() == intlValues[i].ToUpperInvariant())
caseInsensitive = true;
//.........这里部分代码省略.........