Dynamically invoking constructors : Constructor « Reflection « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Reflection;
using System.Reflection.Emit;

public class MainClass
{
    public static void Main()
    {
        ConstructorInfo ci = typeof(string).GetConstructor(new Type[] { typeof(char[]) });
        string s = (string)ci.Invoke(new object[] {new char[] { 'H', 'e', 'l', 'l', 'o' } });
        Console.WriteLine(s);
    }
}
Hello








19.3.Constructor
19.3.1.Get constructor information: Display return type, name and parameters
19.3.2.Find matching constructor
19.3.3.Dynamically invoking constructors
19.3.4.Utilize MyClass without assuming any prior knowledge: invoke constructor
19.3.5.Using a ConstructorInfo to create new instance
19.3.6.Call parent constructor from abstract class
19.3.7.Get the ConstructorInfo object matching the specified binding flags, and displays the signature of the constructor.