MemberInfo.Name Property
.NET Framework 4
Gets the name of the current member.
Assembly: mscorlib (in mscorlib.dll)
Only the simple name of the member is returned, not the fully qualified name.
To get the Name property, get the class Type. From the Type, get the MemberInfo array. From a MemberInfo element of the array, obtain the Name property.
This example lists the Name and DeclaringType property of each member of the specified class.
using System; using System.Reflection; class Mymemberinfo { public static int Main() { Console.WriteLine ("\nReflection.MemberInfo"); // Get the Type and MemberInfo. Type MyType = Type.GetType("System.Empty"); MemberInfo[] Mymemberinfoarray = MyType.GetMembers(); // Get and display the DeclaringType method. Console.Write("\nThere are {0} members in ", Mymemberinfoarray.GetLength(0)); Console.Write("{0}.", MyType.FullName); foreach (MemberInfo Mymemberinfo in Mymemberinfoarray) { Console.Write("\n" + Mymemberinfo.Name + " declaring type - " + Mymemberinfo.DeclaringType); } return 0; } }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Result of the sample
If anybody is curious, here is the result of the sample:$0
$0
Reflection.MemberInfo$0
$0
There are 6 members in System.Empty.$0
ToString declaring type - System.Empty$0
GetObjectData declaring type - System.Empty$0
Equals declaring type - System.Object$0
GetHashCode declaring type - System.Object$0
GetType declaring type - System.Object$0
Value declaring type - System.Empty$0
- 10/20/2010
- Michael Quinlan
- 4/7/2011
- pulido002
