If you have a List where I is the interface, and you add elements like F1 and F2 , where both implement I , then when you extract either of the two elements from the list, you can check the link type using the ** is keyword **, and start applying the proper cast to the element that you got from the list.
For instance:
struct Foo1 : IFoo {...} struct Foo2 : IFoo {...} List<IFoo> listOfFoo = new List<IFoo>(); IFoo foo1 = new Foo1(); IFoo foo2 = new Foo2(); listOfFoo.Add(foo1); listOfFoo.Add(foo2); // lets retrieve the first element and check if it a Foo1 value type if(listOfFoo[0] is Foo1){ // cast element from List to Foo1 Foo1 foo = (Foo1) listOfFoo[0]; }
Since we are dealing with structures, when an item from a list returns to its original value type, it must be unpacked. But too much unboxing and boxing can hit performance, and since you want to do something like collision detection, it can lead to poor performance.
Do you have to use structures? Due to changes in boxing made to variables, it may not behave correctly if you perform operations with objects stored in boxed boxes, and, as I said, too much boxing can bring you bad results.
In my opinion, a class with MemberwiseClone would be better.
You can read this article on MSDN, which details the pros and cons for both structures and classes, this can help you better understand when to use one or the other.
source share