.net - Saving an open generic type in an array? -


i facing problem .net generics. thing want saving array of generics types (graphicsitem):

public class graphicsitem<t> {     private t _item;      public void load(t item)     {         _item = item;     } } 

how can save such open generic type in array?

implement non-generic interface , use that:

public class graphicsitem<t> : igraphicsitem {     private t _item;      public void load(t item)     {         _item = item;     }      public void somethingwhichisnotgeneric(int i)     {         // code goes here...     } }  public interface igraphicsitem {     void somethingwhichisnotgeneric(int i); } 

then use interface item in list:

var values = new list<igraphicsitem>(); 

Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -