0

I have a class

class Class<T>
{
     public Class(T arg)
     {
         print(arg.ToString());
     }
}

Pls Correct me: How to create an instance from this generic class

Type t = typeof(Class<>).MakeGenericType(typeof(string));
Activator.CreateInstance(t,"test");
Voicu
  • 56
  • 5
  • 3
    Possible duplicate of [Pass An Instantiated System.Type as a Type Parameter for a Generic Class](http://stackoverflow.com/questions/266115/pass-an-instantiated-system-type-as-a-type-parameter-for-a-generic-class), [How to dynamically create generic C# object using reflection?](http://stackoverflow.com/questions/1151464/how-to-dynamically-create-generic-c-sharp-object-using-reflection) – Amit Dec 19 '15 at 11:23
  • Your code works fine as it is.. – Rob Dec 19 '15 at 11:26
  • class Class { public Class(ref T arg) { arg = "test"; } } How to be in this case? – Алексей Борисов Dec 19 '15 at 11:32

0 Answers0