本文整理汇总了C#中ReadOnlyDictionary.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# ReadOnlyDictionary.Contains方法的具体用法?C# ReadOnlyDictionary.Contains怎么用?C# ReadOnlyDictionary.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReadOnlyDictionary
的用法示例。
在下文中一共展示了ReadOnlyDictionary.Contains方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestReadOperations
public void TestReadOperations()
{
var dic = new ReadOnlyDictionary<string, string>(new Dictionary<string, string>() {
{"key1", "val1"},
{"key2", "val2"},
{"key3", "val3"},
});
Assert.AreEqual(3, dic.Count);
Assert.AreEqual("val1", dic["key1"]);
Assert.IsTrue(dic.Contains(new KeyValuePair<string, string>("key2", "val2")));
Assert.IsTrue(dic.ContainsKey("key3"));
foreach (var pair in dic) {
}
foreach (var key in dic.Keys) {
}
foreach (var val in dic.Values) {
}
var pairs = new KeyValuePair<string, string>[3];
dic.CopyTo(pairs, 0);
string outval = null;
Assert.IsTrue(dic.TryGetValue("key1", out outval));
Assert.AreEqual(outval, "val1");
}
示例2: ReadOnlyDictionary_Unit_Contains_ValueDoesNotExist
public void ReadOnlyDictionary_Unit_Contains_ValueDoesNotExist()
{
IDictionary<String, String> dictionary = new Dictionary<String, String>() {
{ "Key1", "Value1" },
{ "Key2", "Value2" },
{ "Key3", "Value3" }
};
ReadOnlyDictionary<String, String> target = new ReadOnlyDictionary<String, String>(dictionary);
KeyValuePair<String, String> item = new KeyValuePair<String, String>(dictionary.Keys.First(), "MyValue");
Boolean actual = target.Contains(item);
Assert.AreEqual(false, actual);
}