本文整理汇总了C#中OrderedDictionary.ForEach方法的典型用法代码示例。如果您正苦于以下问题:C# OrderedDictionary.ForEach方法的具体用法?C# OrderedDictionary.ForEach怎么用?C# OrderedDictionary.ForEach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OrderedDictionary
的用法示例。
在下文中一共展示了OrderedDictionary.ForEach方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestOrderedDictionary
/// <summary>
/// OrderedDictionary<TKey,TValue> (NO DUPLICATES)
/// A dictionary based on balanced search tree
/// Add / Find / Remove work in time O(log(N))
/// Provides fast .Range(from,to) operation
/// </summary>
private static void TestOrderedDictionary()
{
OrderedDictionary<int, Student> students = new OrderedDictionary<int, Student>();
var student1 = new Student("First", 21);
var student2 = new Student("Second", 21);
students.Add(5, student1);
students.Add(2, student2);
var student3 = new Student("Third", 22);
var student4 = new Student("Forth", 23);
var student5 = new Student("Fifth", 24);
students.Add(3, student3);
students.Add(4, student4);
students.Add(1, student5);
foreach (var item in students)
{
Console.WriteLine(item);
}
Console.WriteLine("========== Range Key >= 2 && <= 4 ============= ");
var inRangeStudents = students.Range(2, true, 4, true);
foreach (var item in inRangeStudents)
{
Console.WriteLine(item);
}
Console.WriteLine("==========ForEach(x => { x.Value.Age += 1; Console.WriteLine(x); })============= ");
students.ForEach(x => { x.Value.Age += 1; Console.WriteLine(x); });
}