In the following class:
public class Example<T> where T : IComparable {
private T _min;
private T _max;
public Example() {
// _min = T.MinValue;
// _max = T.MaxValue;
}
public Example(T min, T max) {
_min = min;
_max = max;
}
public bool Contains(T val) {
return (val.CompareTo(_min) < 0) && (val.CompareTo(_max) > 0);
}
}
What would be the best way to initialize the members to their type-specific min & max values in the default constructor? I know this puts another constraint on the allowed types for the generic, but that's fine for my purposes.
Additionally, if a type supported infinite values, such as float or double, is there a way to detect this and set the values accordingly?