I was doing my homework and got stuck in some problems with generics and inheritance.
I have a generic red-black tree class, since it's red-black tree its keys should be comparable, so
public class RedBlackTree<T> where T : IComparable<T>
And then I want another class, let's say, an interval tree, which is an augmented version of red-black tree. So I defined the interval like this:
public class Interval<T> : IComparable where T : IComparable<T>
and since interval tree is indeed a red-black tree with intervals as its keys but just with more specific methods, I defined the class like this:
public class IntervalTree<T> : RedBlackTree<Interval<T>> where T : IComparable<T>
But it won't let me do this, it says something like "cannot implicitly convert Interval<T> to System.IComparable<Interval<T>>", but I also can't write something like where Interval<T> : IComparable<Interval<T>>.
How would I do things like this in C#, or if there's no way to do this inheritance in C# what other templates should I use?
Func<T, int>orIComparer<T>/IEqualityComparer<T>as an argument to the constructor, much likeDictionarydoes.class C { class D {} }whereC.Dis now a class.