How to

create instance of object using reflection

Published: 13. December 2008 | Updated: 13. December 2008
License: Microsoft Public License (MS-PL)
Categories: Framework » Reflection
Tags: C# Reflection
Was this snippet helpful for you? YESYES / NONO

Short example how to create instance to specified type with parameters in constructor
Type type = typeof(Exception);
string parameter = "my exception";
Exception ex = Activator.CreateInstance(type, parameter) as Exception;

Console.WriteLine(ex.Message);
Console Output:
my exception
Send us feedback about this snippet »



Related Snippets: