Condividi tramite


MemberInfo.Name Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets the name of the current member.

Namespace:  System.Reflection
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public MustOverride ReadOnly Property Name As String
public abstract string Name { get; }

Property Value

Type: System.String
The name of this member.

Remarks

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.

Examples

This example lists the Name and DeclaringType property of each member of the specified class.

Imports System.Reflection

Class Example
   Public Shared Function Demo(ByVal outputBlock As System.Windows.Controls.TextBlock) As Integer
      outputBlock.Text &= "Reflection.MemberInfo" & vbCrLf

      ' Get the Type and MemberInfo.
      Dim MyType As Type = Type.GetType("System.Empty")
      Dim Examplearray As MemberInfo() = MyType.GetMembers()

      ' Get and display the DeclaringType method.
      outputBlock.Text += String.Format("There are {0} members in {1}", Examplearray.GetLength(0), MyType.FullName) & vbCrLf

      Dim Example As MemberInfo
      For Each Example In Examplearray
         outputBlock.Text &= Example.Name & " declaring type - " & Example.DeclaringType.ToString() & vbCrLf
      Next Example

      Return 0
   End Function
End Class
using System;
using System.Reflection;

class Example
{
   public static int Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      outputBlock.Text += "\nReflection.MemberInfo" + "\n";

      // Get the Type and MemberInfo.
      Type MyType = Type.GetType("System.Empty");
      MemberInfo[] Examplearray = MyType.GetMembers();

      // Get and display the DeclaringType method.
      outputBlock.Text += String.Format("\nThere are {0} members in ",
          Examplearray.GetLength(0));
      outputBlock.Text += String.Format("{0}.", MyType.FullName);

      foreach (MemberInfo Example in Examplearray)
      {
         outputBlock.Text += String.Format("\n" + Example.Name
             + " declaring type - " +
             Example.DeclaringType);
      }

      return 0;
   }
}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.