Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Ruft ein Array mit den Namen der Konstanten einer angegebenen Enumeration ab.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
<ComVisibleAttribute(True)> _
Public Shared Function GetNames ( _
enumType As Type _
) As String()
'Usage
Dim enumType As Type
Dim returnValue As String()
returnValue = Enum.GetNames(enumType)
[ComVisibleAttribute(true)]
public static string[] GetNames (
Type enumType
)
[ComVisibleAttribute(true)]
public:
static array<String^>^ GetNames (
Type^ enumType
)
/** @attribute ComVisibleAttribute(true) */
public static String[] GetNames (
Type enumType
)
ComVisibleAttribute(true)
public static function GetNames (
enumType : Type
) : String[]
Parameter
- enumType
Ein Enumerationstyp.
Rückgabewert
Ein Zeichenfolgenarray mit den Namen der Konstanten von enumType.
Ausnahmen
| Ausnahmetyp | Bedingung |
|---|---|
enumType ist NULL (Nothing in Visual Basic). |
|
Der enumType-Parameter ist keine Enum. |
Hinweise
Die Elemente des Arrays mit den Rückgabewerten sind nach den Werten der Enumerationskonstanten sortiert. Wenn es Enumerationskonstanten mit demselben Wert gibt, ist die Reihenfolge ihrer entsprechenden Namen nicht definiert.
Beispiel
Das folgende Codebeispiel veranschaulicht die Verwendung von GetNames.
Imports System
Public Class GetNamesTest
Enum Colors
Red
Green
Blue
Yellow
End Enum 'Colors
Enum Styles
Plaid
Striped
Tartan
Corduroy
End Enum 'Styles
Public Shared Sub Main()
Console.WriteLine("The values of the Colors Enum are:")
Dim s As String
For Each s In [Enum].GetNames(GetType(Colors))
Console.WriteLine(s)
Next s
Console.WriteLine()
Console.WriteLine("The values of the Styles Enum are:")
For Each s In [Enum].GetNames(GetType(Styles))
Console.WriteLine(s)
Next s
End Sub 'Main
End Class 'GetNamesTest
using System;
public class GetNamesTest {
enum Colors { Red, Green, Blue, Yellow };
enum Styles { Plaid, Striped, Tartan, Corduroy };
public static void Main() {
Console.WriteLine("The values of the Colors Enum are:");
foreach(string s in Enum.GetNames(typeof(Colors)))
Console.WriteLine(s);
Console.WriteLine();
Console.WriteLine("The values of the Styles Enum are:");
foreach(string s in Enum.GetNames(typeof(Styles)))
Console.WriteLine(s);
}
}
using namespace System;
enum class Colors
{
Red, Green, Blue, Yellow
};
enum class Styles
{
Plaid, Striped, Tartan, Corduroy
};
int main()
{
Console::WriteLine( "The values of the Colors Enum are:" );
Array^ a = Enum::GetNames( Colors::typeid );
Int32 i = 0;
do
{
Object^ o = a->GetValue( i );
Console::WriteLine( o->ToString() );
}
while ( ++i < a->Length );
Console::WriteLine();
Console::WriteLine( "The values of the Styles Enum are:" );
Array^ b = Enum::GetNames( Styles::typeid );
i = 0;
do
{
Object^ o = b->GetValue( i );
Console::WriteLine( o->ToString() );
}
while ( ++i < b->Length );
}
import System.*;
public class GetNamesTest
{
enum Colors
{
red (0),
green (1),
blue (2),
yellow (3);
} //Colors
enum Styles
{
plaid (0),
striped (1),
tartan (2),
corduroy (3);
} //Styles
public static void main(String[] args)
{
Console.WriteLine("The values of the Colors Enum are:");
String s[] = Enum.GetNames(Colors.class.ToType());
for (int iCtr = 0; iCtr < s.length; iCtr++) {
Console.WriteLine(s[iCtr]);
}
Console.WriteLine();
Console.WriteLine("The values of the Styles Enum are:");
String s1[] = Enum.GetNames(Styles.class.ToType());
for (int iCtr = 0; iCtr < s.length; iCtr++) {
Console.WriteLine(s1[iCtr]);
}
} //main
} //GetNamesTest
import System;
public class GetNamesTest {
enum Colors { Red, Green, Blue, Yellow };
enum Styles { Plaid, Striped, Tartan, Corduroy };
public static function Main() {
Console.WriteLine("The values of the Colors Enum are:");
for(var i : int in Enum.GetNames(Colors))
Console.WriteLine(Enum.GetNames(Colors).GetValue(i));
Console.WriteLine();
Console.WriteLine("The values of the Styles Enum are:");
for(var j : int in Enum.GetNames(Styles))
Console.WriteLine(Enum.GetNames(Styles).GetValue(j));
}
}
Plattformen
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0