Search code examples
c#interfacewhere-clauseconstraintsienumerable

How do I create a C# interface for T where T extends IComparable<T> and the interface extends IEnumerable<T>


What is the C# equivalent to the following java construct:

interface LinkedList<T extends Comparable<T>> extends Iterable<T>

I cannot do this the following way in C# because it is assumed that IEnumerable<T>belongs to where constraint:

interface LinkedList<T> where T : IComparable<T>, IEnumerable <T>

How can I do this in C# ?


Solution

  • I think you're looking for something like this:

    interface IInterface<T> : IEnumerable<T> 
        where T : IComparable<T>
    {
        // implementation here
    }