C# Type GetMethods()

Description

Type GetMethods() returns all the public methods of the current Type.

Syntax

Type.GetMethods() has the following syntax.


public MethodInfo[] GetMethods()

Returns

Type.GetMethods() method returns

Example


using System;/*w  w  w.j a v a  2s.co m*/
using System.Reflection;
using System.Reflection.Emit;

public class MyTypeClass
{
    public void MyMethods()
    {
    }
    public int MyMethods1() 
    {
        return 3;
    }
    protected String MyMethods2()
    {
        return "hello";
    }
}
public class TypeMain
{
    public static void Main() 
    {
        Type myType =(typeof(MyTypeClass));
        MethodInfo[] myArrayMethodInfo = myType.GetMethods();
        Console.WriteLine(myArrayMethodInfo.Length);

    }
}

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