本文整理汇总了C#中System.Tuple<T1>.IStructuralComparable.CompareTo方法的典型用法代码示例。如果您正苦于以下问题:C# Tuple<T1>.IStructuralComparable.CompareTo方法的具体用法?C# Tuple<T1>.IStructuralComparable.CompareTo怎么用?C# Tuple<T1>.IStructuralComparable.CompareTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了Tuple<T1>.IStructuralComparable.CompareTo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Compare
//引入命名空间
using System;
using System.Collections.Generic;
public class DescendingComparer<T> : IComparer<T>
{
public int Compare(T x, T y)
{
return -1 * Comparer<T>.Default.Compare(x, y);
}
}
class CompareTo2
{
static void Main()
{
Tuple<Double>[] values = { Tuple.Create(13.54),
Tuple.Create(Double.NaN),
Tuple.Create(-189.42993),
Tuple.Create(Double.PositiveInfinity),
Tuple.Create(Double.Epsilon),
Tuple.Create(1.934E-17),
Tuple.Create(Double.NegativeInfinity),
Tuple.Create(-0.000000000003588),
null };
Console.WriteLine("The values in unsorted order:");
foreach (var value in values)
if (value != null)
Console.WriteLine(" {0}", value.Item1);
else
Console.WriteLine(" <null>");
Console.WriteLine();
Array.Sort(values, new DescendingComparer<Tuple<Double>>());
Console.WriteLine("The values sorted in descending order:");
foreach (var value in values)
if (value != null)
Console.WriteLine(" {0}", value.Item1);
else
Console.WriteLine(" <null>");
}
}
输出:
The values in unsorted order: 13.54 NaN -189.42993 Infinity 4.94065645841247E-324 1.934E-17 -Infinity -3.588E-12 The values sorted in descending order: Infinity 13.54 1.934E-17 4.94065645841247E-324 -3.588E-12 -189.42993 -Infinity NaN