C# TypeInfo GetMembers()

Description

TypeInfo GetMembers() Returns all the public members of the current Type.

Syntax

TypeInfo.GetMembers() has the following syntax.


public MemberInfo[] GetMembers()

Returns

TypeInfo.GetMembers() method returns

Example


using System.Reflection;
using System;/*from  w  ww  .  ja va  2  s .  c o m*/
class MyClass
{
    public int myInt = 0;
    public string myString = null;

    public MyClass()
    {
    }
    public void Myfunction()
    {
    }
}

class Type_GetMembers
{
    public static void Main()
    {
        MyClass myObject = new MyClass();
        MemberInfo[] myMemberInfo;

        Type myType = myObject.GetType();

        myMemberInfo = myType.GetMembers();

        Console.WriteLine("\nThe members of class '{0}' are :\n", myType);
        for (int i = 0; i < myMemberInfo.Length; i++)
        {
            Console.WriteLine("'{0}' is a {1}", myMemberInfo[i].Name, myMemberInfo[i].MemberType);
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Reflection »




EventInfo
FieldInfo
MemberInfo
MethodInfo
ParameterInfo
TypeInfo