本文整理汇总了C#中Tuple.ToSublist方法的典型用法代码示例。如果您正苦于以下问题:C# Tuple.ToSublist方法的具体用法?C# Tuple.ToSublist怎么用?C# Tuple.ToSublist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tuple
的用法示例。
在下文中一共展示了Tuple.ToSublist方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestStableSortCopy_SortRandomList_TinyBuffer_KeepEquivalentItemsOrdered
public void TestStableSortCopy_SortRandomList_TinyBuffer_KeepEquivalentItemsOrdered()
{
Random random = new Random();
// build a list
var list = new List<Tuple<int, int>>(100);
Sublist.Generate(100, i => Tuple.Create(random.Next(100), i)).AddTo(list.ToSublist());
// sort the list
Tuple<int, int>[] buffer = new Tuple<int, int>[3]; // no space to merge - bad for performance!
var destination = new Tuple<int, int>[100];
list.ToSublist().StableSort(buffer.ToSublist()).CopyTo(destination.ToSublist());
// first make sure the list is sorted by the first value
bool isFirstSorted = destination.ToSublist().IsSorted((t1, t2) => Comparer<int>.Default.Compare(t1.Item1, t2.Item1));
Assert.IsTrue(isFirstSorted, "The items were not sorted according to the first item.");
// then make sure the list is sorted by the second value
// tuples compare by first comparing the first items, then, if necessary, the second items
bool isSorted = destination.ToSublist().IsSorted();
Assert.IsTrue(isSorted, "The equivalent items did not remain in the same order.");
}