C# TypeInfo GetConstructors()

Description

TypeInfo GetConstructors() Returns all the public constructors defined for the current Type.

Syntax

TypeInfo.GetConstructors() has the following syntax.


[ComVisibleAttribute(true)]
public ConstructorInfo[] GetConstructors()

Returns

TypeInfo.GetConstructors() method returns

Example


using System;/*www  .  ja  v  a2  s  . co  m*/
using System.Reflection;

public class t {
    public t() {}
    static t() {}
    public t(int i) {}

    public static void Main() {
        ConstructorInfo[] p = typeof(t).GetConstructors();
        Console.WriteLine(p.Length);

        for (int i=0;i<p.Length;i++) {
            Console.WriteLine(p[i].IsStatic);
        }
        p = typeof(t).GetConstructors(
           BindingFlags.Public | BindingFlags.Static |
           BindingFlags.NonPublic | BindingFlags.Instance);
        Console.WriteLine(p.Length);

        for (int i=0;i<p.Length;i++) {
            Console.WriteLine(p[i].IsStatic);
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Reflection »




EventInfo
FieldInfo
MemberInfo
MethodInfo
ParameterInfo
TypeInfo