C# 泛型接口扩展(以IComparable<T>为
public static class Comparable
{
public static bool LessThan<T>(this T left, T right) where T : IComparable<T>
{
return left.CompareTo(right) < 0;
}
public static bool GreaterThan<T>(this T left, T right) where T : IComparable<T>
{
return left.CompareTo(right) > 0;
}
public static bool LessThanEqual<T>(this T left, T right) where T : IComparable<T>
{
return left.CompareTo(right) <= 0;
}
public static bool GreaterThanEqual<T>(this T left, T right) where T : IComparable<T>
{
return left.CompareTo(right) >= 0;
}
}
本文标题:C# 泛型接口扩展(以IComparable<T>为
本文链接:https://www.haomeiwen.com/subject/dfjukttx.html
网友评论