C# TypeInfo GetConstructors(BindingFlags)

Description

TypeInfo GetConstructors(BindingFlags) When overridden in a derived class, searches for the constructors defined for the current Type, using the specified BindingFlags.

Syntax

TypeInfo.GetConstructors(BindingFlags) has the following syntax.


[ComVisibleAttribute(true)]
public abstract ConstructorInfo[] GetConstructors(
  BindingFlags bindingAttr
)

Parameters

TypeInfo.GetConstructors(BindingFlags) has the following parameters.

  • bindingAttr - A bitmask comprised of one or more BindingFlags that specify how the search is conducted.
  • bindingAttr - -or-
  • bindingAttr - Zero, to return null.

Returns

TypeInfo.GetConstructors(BindingFlags) method returns

Example


using System;/*from w  w w . j a  v  a 2 s.  c  o 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