0

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

3
  • attention that, i want a list of any type of T Commented Jan 25, 2018 at 5:22
  • 2
    You need to define T also in IMyInterfaces Commented Jan 25, 2018 at 5:24
  • if i define T, i lose my list that can store any type of IMyInterface Commented Jan 25, 2018 at 5:45

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

3 Comments

You mean there is no way to, i have a list of interface<T> that interface<T> may be any type?
You could use IMyInterface<object>, and anything can be cast to object.
Then no, you either make IMyInterfaces generic as well or you specify a concrete generic parameter for IMyInterface. There is no way to declare something with a free generic type parameter

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.