How am I able to create A List<T> containing a generic Interface?

Posted by Conrad Clark on Stack Overflow See other posts from Stack Overflow or by Conrad Clark
Published on 2010-12-23T18:50:57Z Indexed on 2010/12/23 18:54 UTC
Read the original article Hit count: 284

Filed under:
|
|
|

I have a List which must contain IInteract Objects. But IInteract is a generic interface which requires 2 type arguments.

My main idea is iterate through a list of Objects and "Interact" one with another if they didn't interact yet. So i have this object

List<IObject> WorldObjects = new List<IObject>();

and this one:

private List<IInteract> = new List<IInteract>();

Except I can't compile the last line because IInteract requires 2 type arguments. But I don't know what the arguments are until I add them. I could add interactions between Objects of Type A and A... or Objects of Type B and C.

I want to create "Interaction" classes which do something with the "acting" object and the "target" object, but I want them to be independent from the objects... so I could add an Interaction between for instance... "SuperUltraClass" and... an "integer".

Am I using the wrong approach?

© Stack Overflow or respective owner

Related posts about c#

Related posts about list