Call GetConstructor to get the constructor : ConstructorInfo : Reflection C# Source Code


Custom Search

C# Source Code » Reflection » ConstructorInfo »

 

Call GetConstructor to get the constructor








    
 
using System;
using System.Text;
using System.Reflection;

class MainClass
{
    public static StringBuilder CreateStringBuilder()
    {
        Type type = typeof(StringBuilder);

        Type[] argTypes = new Type[] { typeof(System.String), typeof(System.Int32) };

        ConstructorInfo cInfo = type.GetConstructor(argTypes);

        object[] argVals = new object[] { "Some string", 30 };
        StringBuilder sb = (StringBuilder)cInfo.Invoke(argVals);

        return sb;
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Reflection
» ConstructorInfo