本文整理汇总了C#中RedBlackTree.TryGetValue方法的典型用法代码示例。如果您正苦于以下问题:C# RedBlackTree.TryGetValue方法的具体用法?C# RedBlackTree.TryGetValue怎么用?C# RedBlackTree.TryGetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedBlackTree
的用法示例。
在下文中一共展示了RedBlackTree.TryGetValue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddItem
public void AddItem()
{
RedBlackTree<int, int> tree = new RedBlackTree<int, int>();
int temp;
tree.Add(1, 1);
Assert.AreEqual(tree.Count, 1);
Assert.IsTrue(tree.TryGetValue(1, out temp));
Assert.IsFalse(tree.TryGetValue(2, out temp));
}
示例2: RemoveNonExistingItem
public void RemoveNonExistingItem()
{
RedBlackTree<int, int> tree = new RedBlackTree<int, int>();
tree.Add(1, 1);
int temp;
bool removed = tree.Remove(2);
Assert.IsFalse (removed);
Assert.AreEqual(tree.Count, 1);
Assert.IsTrue(tree.TryGetValue(1, out temp));
Assert.IsFalse(tree.TryGetValue(2, out temp));
}
示例3: Simple
public void Simple()
{
var redBlackTree = new RedBlackTree<int, string>();
string value;
for (var i = 0; i < 100; i++)
{
redBlackTree.Add(i, i.ToString());
Assert.AreEqual(redBlackTree.Count, i + 1);
Assert.IsTrue(redBlackTree.TryGetValue(i, out value));
Assert.AreEqual(value, i.ToString());
}
Assert.IsFalse(redBlackTree.TryGetValue(101, out value));
Assert.IsNull(value);
Assert.IsFalse(redBlackTree.TryGetValue(102, out value));
Assert.IsNull(value);
}
示例4: TryGetValueExample
public void TryGetValueExample()
{
// Build a simple tree.
var tree = new RedBlackTree<string, int>
{
new KeyValuePair<string, int>("cat", 1),
new KeyValuePair<string, int>("dog", 2),
new KeyValuePair<string, int>("canary", 3)
};
int value;
// We'll get the value for cat successfully.
Assert.IsTrue(tree.TryGetValue("cat", out value));
// And the value should be 1.
Assert.AreEqual(1, value);
// But we won't get a horse
Assert.IsFalse(tree.TryGetValue("horse", out value));
}