哪个版本更好:通用约束
using System;
namespace Utils.Extensions
{
public static class EnumerableExtensions
{
public static bool Between<T>(this T item, T min, T max) where T : IComparable<T>
{
return item.CompareTo(min) >= 0 && item.CompareTo(max) <= 0;
}
}
}
或
using System;
namespace Utils.Extensions
{
public static class EnumerableExtensions
{
public static bool Between<T>(this IComparable<T> item, T min, T max)
{
return item.CompareTo(min) >= 0 && item.CompareTo(max) <= 0;
}
}
}
我认为两者都应该工作,但哪一个我应该使用?
定义“更好”。更高级的预设?可读?还有别的吗? – Oded 2011-01-12 11:06:35
我想他们的表现差异可以忽略不计。我正在考虑更多的优雅或可读性。 – 2011-01-12 11:10:48