C# Type GetMembers()
Description
Type GetMembers()
returns all the public members of the
current Type.
Syntax
Type.GetMembers()
has the following syntax.
public MemberInfo[] GetMembers()
Returns
Type.GetMembers()
method returns
Example
The following code example demonstrates how to use the GetMembers() method overload to collect information about all public members of a specified class.
using System;//from ww w. j a v a 2 s.co m
using System.Reflection;
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();
Type myType = myObject.GetType();
MemberInfo[] myMemberInfo = myType.GetMembers();
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.