interface and generics C#

I have a interface like this:

public interface IMyInterface<T> where T:class
    {

        long OS { get; set; }

        T App { get; set; }
    }

and another interface like this:

public interface IMyInterfaces
    {
        List<IMyInterface<T>> Subscribers { get; set; } //this line give me error
    }

I got error

Upvotes: 0

Views: 54

Answers (1)

Titian Cernicova-Dragomir
Titian Cernicova-Dragomir

Reputation: 249476

You need to specify a concrete type or another generic parameter for T when you use IMyInterface<T>

public interface IMyInterfaces
{
    List<IMyInterface<int>> Subscribers { get; set; }
}

OR

public interface IMyInterfaces<TOther>
{
    List<IMyInterface<TOther>> Subscribers { get; set; }
}

Note I used TOther to stress that it is another generic parameter, different from the T in IMyInterface but you could use the same name (T) for TOther

Upvotes: 4

Related Questions