Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create an instance of an arbitrary Array type at runtime?

I'm trying to deserialize an array of an type unknown at compile time. At runtime I've discovered the type, but I don't know how to create an instance.

Something like:

Object o = Activator.CreateInstance(type); 

which doesn't work because there is no parameterless constructor, Array doesn't seem to have any constructor.

like image 360
CrashCodes Avatar asked Dec 30 '08 17:12

CrashCodes


1 Answers

Use Array.CreateInstance.

like image 87
Jon Skeet Avatar answered Oct 04 '22 13:10

Jon Skeet