Create a Generic List of Generic objects in C# -
I have a generic class for which I would like to create a general list, where the underlying classes apply the same interface However, all of the given interface is not implemented.
Describing the problem would be an easy example. } I'm unable to create a list of things which is a way of putting two things that apply the same interface in the general collection, while The interface is not currently interrupted to protect the generic tog class. It is possible if you use it: Note that this is only possible when using
internal Interface IGenericThing & lt; Out T & gt; {} Internal category generic typing & lt; T & gt; : IGenericThing & lt; T & gt; {} Zero main () {var thing1 = new genericizing & lt; This Taking & gt; (); Var thing2 = new generic typing & lieutenant; That Typing & gt; (); Var Talk 3 = New Generic Ting & lt; SomethingElse & gt; (); Var Talk List = New List & lt; IGenericThing & lt; ISomething & gt; & Gt; () {Thing1, thing2}; }
T only
IGenericThing & lt; T & gt; is done as an output, never in the form of an input! (It is unused, as my example is also acceptable, though, obviously, useless)
Comments
Post a Comment