Retrieves an array of the values of the constants in a specified enumeration.
Namespace:
System
Assembly:
mscorlib (in mscorlib.dll)
Visual Basic (Declaration)
<ComVisibleAttribute(True)> _
Public Shared Function GetValues ( _
enumType As Type _
) As Array
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
)
public static function GetValues(
enumType : Type
) : Array
Return Value
Type:
System..::.ArrayAn Array of the values of the constants in enumType. The elements of the array are sorted by the binary values of the enumeration constants.
The following example illustrates the use of GetValues.
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
Console.WriteLine()
Console.WriteLine("The values of the Styles Enum are:")
For Each i In [Enum].GetValues(GetType(Styles))
Console.WriteLine(i)
Next
End Sub
End Class
' The example produces the following output:
' The values of the Colors Enum are:
' 0
' 1
' 2
' 3
'
' The values of the Styles Enum are:
' 0
' 23
' 65
' 78
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);
}
}
// The example produces the following output:
// The values of the Colors Enum are:
// 0
// 1
// 2
// 3
//
// The values of the Styles Enum are:
// 0
// 23
// 65
// 78
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" ) );
}
}
// The example produces the following output:
// The values of the Colors Enum are:
// 0
// 1
// 2
// 3
//
// The values of the Styles Enum are:
// 0
// 23
// 65
// 78
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));
}
}
// The example produces the following output:
// The values of the Colors Enum are:
// 0
// 1
// 2
// 3
//
// The values of the Styles Enum are:
// 0
// 23
// 65
// 78
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Reference