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. Intermediate Interface Isoming {} Internal Segment Type: ISOMTI {} Internal Square Theatings: Isoming {} Internal Class SomethingElse {} Internal Square Generic Tings & lt; T & gt; {} Internal range DoThings {void Main ()} {var thing1 = New GenericTeat; This lesson & gt; (); Var thing2 = new generic typing & lieutenant; That Typing & gt; (); Var Talk 3 = New Generic Ting & lt; SomethingElse & gt; (); ** var thingList = new list & lt; Generic typing & lt; ISomething & gt; & Gt; () {Thing1, thing2}; **}

}

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:

  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}; }   

Note that this is only possible when using 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

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -