日期:2014-05-18 浏览次数:21124 次
static void Main() { int i = 3; double d = 2.3; if (i.In(2, 4, 5).And(d.Between(2.0, 5.3)).Or(i > d)) MessageBox.Show("Hi!"); } public static bool In<T>(this T value, params T[] values) { return values.Contains(value); } public static bool Between<T>(this T i, T start, T end) where T : IComparable<T> { return i.CompareTo(start) >= 0 && i.CompareTo(end) <= 0; } public static bool And(this bool left, bool right) { return left && right; } public static bool Or(this bool left, bool right) { return left || right; }