本文整理汇总了C#中System.Collections.Generic.IComparer<T>接口的典型用法代码示例。如果您正苦于以下问题:C# IComparer<T>接口的具体用法?C# IComparer<T>怎么用?C# IComparer<T>使用的例子?那么恭喜您, 这里精选的接口代码示例或许可以为您提供帮助。
IComparer<T>接口属于System.Collections.Generic命名空间,在下文中一共展示了IComparer<T>接口的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Compare
// This class is not demonstrated in the Main method
// and is provided only to show how to implement
// the interface. It is recommended to derive
// from Comparer<T> instead of implementing IComparer<T>.
public class BoxComp : IComparer<Box>
{
// Compares by Height, Length, and Width.
public int Compare(Box x, Box y)
{
if (x.Height.CompareTo(y.Height) != 0)
{
return x.Height.CompareTo(y.Height);
}
else if (x.Length.CompareTo(y.Length) != 0)
{
return x.Length.CompareTo(y.Length);
}
else if (x.Width.CompareTo(y.Width) != 0)
{
return x.Width.CompareTo(y.Width);
}
else
{
return 0;
}
}
}