本文整理汇总了C#中ConcurrentDictionary.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# ConcurrentDictionary.Contains方法的具体用法?C# ConcurrentDictionary.Contains怎么用?C# ConcurrentDictionary.Contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConcurrentDictionary
的用法示例。
在下文中一共展示了ConcurrentDictionary.Contains方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestLockFreeDictionary
public void TestLockFreeDictionary()
{
IDictionary<int, Guid> dict = new ConcurrentDictionary<int, Guid>();
KeyValuePair<int, Guid> test = new KeyValuePair<int, Guid>(-64, Guid.NewGuid());
dict.Add(42, Guid.NewGuid());
dict.Add(22, Guid.NewGuid());
dict.Add(test);
dict.Add(55, Guid.NewGuid());
Assert.IsTrue(dict.ContainsKey(-64));
Assert.IsTrue(dict.Contains(test));
Assert.IsFalse(dict.Contains(new KeyValuePair<int, Guid>(-64, new Guid())));
dict[-64] = Guid.NewGuid();
Assert.IsFalse(dict.Contains(test));
Guid newID = Guid.NewGuid();
dict[12] = newID;
Guid id = dict[12];
Assert.IsTrue(newID == id);
Assert.IsTrue(dict.Count == 5);
dict.Remove(-64);
Assert.IsTrue(dict.Count == 4);
}
示例2: Contains_KeyValuePairThrowsNotImplementedException
public void Contains_KeyValuePairThrowsNotImplementedException()
{
// Arrange
ConcurrentDictionary<int, int> dictionary = new ConcurrentDictionary<int, int>();
// Act/Assert
Assert.Throws<NotImplementedException>(() => dictionary.Contains(new KeyValuePair<int, int>(0, 0)));
}
示例3: PairCollide
public void PairCollide()
{
var firstPair = new KeyValuePair<string, string>("key", "validValue");
var secondPair = new KeyValuePair<string, string>("key", "wrongValue");
IDictionary<string, string> dict = new ConcurrentDictionary<string, string>();
dict.Add(firstPair);
Assert.Throws<ArgumentException>(() => dict.Add(secondPair));
Assert.IsTrue(dict.Contains(firstPair));
Assert.IsFalse(dict.Contains(secondPair));
}