I want to create an interface that works for all the IComparable types. For example
public interface SortAlgorithm where T : System.IComparable
All derived generic classes will also have to implement the generic constraint.
Therefore, you should declare the class as:
public class InsertionSort<T> : SortAlgorithm<T> where T : System.IComparable<T>
What the error basically says is that the generic parameter T
(which at this point can be any class or struct) is not guaranteed to implement IComparable<T>
, as constrained by the base class (the SortAlgorithm
interface).
You can provide this guarantee by specifying the constraint on the InsertionSort
class as well, as presented above.