Enum.GetValues-Methode
Ruft ein Array mit den Werten der Konstanten einer angegebenen Enumeration ab.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
<ComVisibleAttribute(True)> _
Public Shared Function GetValues ( _
enumType As Type _
) As Array
'Usage
Dim enumType As Type
Dim returnValue As Array
returnValue = Enum.GetValues(enumType)
[ComVisibleAttribute(true)]
public static Array GetValues (
Type enumType
)
[ComVisibleAttribute(true)]
public:
static Array^ GetValues (
Type^ enumType
)
/** @attribute ComVisibleAttribute(true) */
public static Array GetValues (
Type enumType
)
ComVisibleAttribute(true)
public static function GetValues (
enumType : Type
) : Array
Parameter
- enumType
Ein Enumerationstyp.
Rückgabewert
Ein Array mit den Werten der Konstanten von enumType. Die Elemente des Arrays sind nach den Werten der Enumerationskonstanten sortiert.
Ausnahmen
Ausnahmetyp | Bedingung |
---|---|
enumType ist NULL (Nothing in Visual Basic). |
|
enumType ist keine Enum. |
Beispiel
Das folgende Codebeispiel veranschaulicht die Verwendung von GetValues.
Imports System
Public Class GetValuesTest
Enum Colors
Red
Green
Blue
Yellow
End Enum 'Colors
Enum Styles
Plaid = 0
Striped = 23
Tartan = 65
Corduroy = 78
End Enum 'Styles
Public Shared Sub Main()
Console.WriteLine("The values of the Colors Enum are:")
Dim i As Integer
For Each i In [Enum].GetValues(GetType(Colors))
Console.WriteLine(i)
Next i
Console.WriteLine()
Console.WriteLine("The values of the Styles Enum are:")
For Each i In [Enum].GetValues(GetType(Styles))
Console.WriteLine(i)
Next i
End Sub 'Main
End Class 'GetValuesTest
using System;
public class GetValuesTest {
enum Colors { Red, Green, Blue, Yellow };
enum Styles { Plaid = 0, Striped = 23, Tartan = 65, Corduroy = 78 };
public static void Main() {
Console.WriteLine("The values of the Colors Enum are:");
foreach(int i in Enum.GetValues(typeof(Colors)))
Console.WriteLine(i);
Console.WriteLine();
Console.WriteLine("The values of the Styles Enum are:");
foreach(int i in Enum.GetValues(typeof(Styles)))
Console.WriteLine(i);
}
}
using namespace System;
enum class Colors
{
Red, Green, Blue, Yellow
};
enum class Styles
{
Plaid = 0,
Striped = 23,
Tartan = 65,
Corduroy = 78
};
int main()
{
Console::WriteLine( "The values of the Colors Enum are:" );
Array^ a = Enum::GetValues( Colors::typeid );
for ( Int32 i = 0; i < a->Length; i++ )
{
Object^ o = a->GetValue( i );
Console::WriteLine( "{0}", Enum::Format( Colors::typeid, o, "D" ) );
}
Console::WriteLine();
Console::WriteLine( "The values of the Styles Enum are:" );
Array^ b = Enum::GetValues( Styles::typeid );
for ( Int32 i = 0; i < b->Length; i++ )
{
Object^ o = b->GetValue( i );
Console::WriteLine( "{0}", Enum::Format( Styles::typeid, o, "D" ) );
}
}
import System.*;
public class GetValuesTest
{
enum Colors
{
red (0),
green (1),
blue (2),
yellow (3);
} //Colors
enum Styles
{
plaid (0),
striped (23),
tartan (65),
corduroy (78);
} //Styles
public static void main(String[] args)
{
Console.WriteLine("The values of the Colors Enum are:");
Array a = Enum.GetValues(Colors.class.ToType());
for (int iCtr = 0; iCtr < a.get_Length(); iCtr++) {
Int32 i =( Int32)a.GetValue(iCtr);
Console.WriteLine(i);
}
Console.WriteLine();
Console.WriteLine("The values of the Styles Enum are:");
Array a1 = Enum.GetValues(Styles.class.ToType());
for (int iCtr = 0; iCtr < a1.get_Length(); iCtr++) {
Int32 i =( Int32)a1.GetValue(iCtr);
Console.WriteLine(i);
}
} //main
} //GetValuesTest
import System;
public class GetValuesTest {
enum Colors { Red, Green, Blue, Yellow };
enum Styles { Plaid = 0, Striped = 23, Tartan = 65, Corduroy = 78 };
public static function Main() {
Console.WriteLine("The values of the Colors Enum are:");
for(var i : int in Enum.GetValues(Colors))
Console.WriteLine(Enum.GetValues(Colors).GetValue(i));
Console.WriteLine();
Console.WriteLine("The values of the Styles Enum are:");
for(var j : int in Enum.GetValues(Styles))
Console.WriteLine(Enum.GetValues(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