MemberInfo.Name 属性
获取当前成员的名称。
**命名空间:**System.Reflection
**程序集:**mscorlib(在 mscorlib.dll 中)
语法
声明
Public MustOverride ReadOnly Property Name As String
用法
Dim instance As MemberInfo
Dim value As String
value = instance.Name
public abstract string Name { get; }
public:
virtual property String^ Name {
String^ get () abstract;
}
/** @property */
public abstract String get_Name ()
public abstract function get Name () : String
属性值
包含此成员名称的 String。
备注
只返回成员的简单名称,不返回完全限定名。
若要获取 Name 属性,请获取 Type 类。从 Type 获取 MemberInfo 数组。从该数组的 MemberInfo 元素获取 Name 属性。
示例
此示例列出了指定类的每个成员的 Name 和 DeclaringType 属性。
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
Class Mymemberinfo
Public Shared Function Main() As Integer
Console.WriteLine("Reflection.MemberInfo")
' Get the Type and MemberInfo.
Dim MyType As Type = Type.GetType("System.Empty")
Dim Mymemberinfoarray As MemberInfo() = MyType.GetMembers()
' Get and display the DeclaringType method.
Console.WriteLine("There are {0} members in {1}", Mymemberinfoarray.GetLength(0), MyType.FullName)
Dim Mymemberinfo As MemberInfo
For Each Mymemberinfo In Mymemberinfoarray
Console.WriteLine(Mymemberinfo.Name & " declaring type - " & Mymemberinfo.DeclaringType.ToString())
Next Mymemberinfo
Return 0
End Function
End 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;
}
}
using namespace System;
using namespace System::Reflection;
int main()
{
Console::WriteLine( "\nReflection.MemberInfo" );
// Get the Type and MemberInfo.
Type^ MyType = Type::GetType( "System.Empty" );
array<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 );
System::Collections::IEnumerator^ enum0 = Mymemberinfoarray->GetEnumerator();
while ( enum0->MoveNext() )
{
MemberInfo^ Mymemberinfo = safe_cast<MemberInfo^>(enum0->Current);
Console::Write( "\n{0} declaring type - {1}", Mymemberinfo->Name, Mymemberinfo->DeclaringType );
}
}
import System.*;
import System.Reflection.*;
class MyMemberInfo
{
public static void main(String[] args)
{
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 ",
String.valueOf(myMemberInfoArray.GetLength(0)));
Console.Write("{0}.", myType.get_FullName());
for (int iCtr=0; iCtr < myMemberInfoArray.length; iCtr++) {
MemberInfo myMemberInfo = myMemberInfoArray[iCtr];
Console.Write(("\n" + myMemberInfo.get_Name()
+ " declaring type - " + myMemberInfo.get_DeclaringType()));
}
} //main
} //MyMemberInfo
import System;
import System.Reflection;
class Mymemberinfo
{
public static function Main() : void
{
Console.WriteLine ("\nReflection.MemberInfo");
//Get the Type and MemberInfo.
var MyType : Type = Type.GetType("System.Empty");
var Mymemberinfoarray : MemberInfo[] = MyType.GetMembers();
//Get and display the DeclaringType method.
Console.Write("\nThere are {0} members in ",
Mymemberinfoarray.GetLength(0));
Console.Write("{0}.", MyType.FullName);
for (var i : int in Mymemberinfoarray)
{
var Mymemberinfo : MemberInfo = Mymemberinfoarray[i];
Console.Write("\n" + Mymemberinfo.Name
+ " declaring type - " +
Mymemberinfo.DeclaringType);
}
}
}
Mymemberinfo.Main();
平台
Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
.NET Compact Framework
受以下版本支持:2.0、1.0