本文整理汇总了C#中RedBlackTree.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# RedBlackTree.GetEnumerator方法的具体用法?C# RedBlackTree.GetEnumerator怎么用?C# RedBlackTree.GetEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedBlackTree
的用法示例。
在下文中一共展示了RedBlackTree.GetEnumerator方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NonIComparable
public void NonIComparable()
{
var redBlackTree = new RedBlackTree<NonComparableTClass, string>();
for (var i = 0; i < 100; i++)
{
redBlackTree.Add(new NonComparableTClass(i), i.ToString());
}
var newTree = SerializeUtil.BinarySerializeDeserialize(redBlackTree);
Assert.AreNotSame(redBlackTree, newTree);
Assert.AreEqual(redBlackTree.Count, newTree.Count);
var redBlackTreeEnumerator = redBlackTree.GetEnumerator();
var newTreeEnumerator = newTree.GetEnumerator();
while (redBlackTreeEnumerator.MoveNext())
{
Assert.IsTrue(newTreeEnumerator.MoveNext());
Assert.AreEqual(redBlackTreeEnumerator.Current.Key.Number, newTreeEnumerator.Current.Key.Number);
Assert.AreEqual(redBlackTreeEnumerator.Current.Value, newTreeEnumerator.Current.Value);
Assert.IsTrue(newTree.ContainsKey(redBlackTreeEnumerator.Current.Key));
Assert.AreEqual(newTree[redBlackTreeEnumerator.Current.Key], redBlackTreeEnumerator.Current.Value);
}
Assert.IsFalse(newTreeEnumerator.MoveNext());
}
示例2: GetEnumeratorExample
public void GetEnumeratorExample()
{
var tree = new RedBlackTree<string, int>
{
new KeyValuePair<string, int>("cat", 1),
new KeyValuePair<string, int>("dog", 2),
new KeyValuePair<string, int>("canary", 3)
};
var enumerator = tree.GetEnumerator();
// Enumerate through the items in the tree, and write the contents
// to the standard output.
while (enumerator.MoveNext())
{
System.Console.Write("Key : ");
System.Console.WriteLine(enumerator.Current.Key);
System.Console.Write("Value : ");
System.Console.WriteLine(enumerator.Current.Value);
}
}