C# Type GetConstructors()

Description

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

Syntax

Type.GetConstructors() has the following syntax.


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

Returns

Type.GetConstructors() method returns

Example

This example shows the output of the GetConstructors overload from a class that has two instance constructors and one static constructor.


//  w w  w.j  a va 2 s.co m
using System;
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);
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version