Trying to define constraint on class, but get error:
public class Utilities3<T> where T : IComparable
{
public T Max<T>(T a, T b)
{
return a.CompareTo(b) > 0 ? a : b;
}
}
'T' does not contain a definition for 'CompareTo' and no extension method 'CompareTo' accepting a first argument of type 'T' could be found (are you missing a using directive or an assembly reference?)
Cannot resolve symbol 'CompareTo'
While constraint on function works fine:
public class Utilities2<T>
{
public T Max<T>(T a, T b) where T : IComparable
{
return a.CompareTo(b) > 0 ? a : b;
}
}
Why constraint on class not working?
