Export (0) Print
Expand All

Enum.GetValues Method

Retrieves an array of the values of the constants in a specified enumeration.

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

[ComVisibleAttribute(true)]
public static Array GetValues(
	Type enumType
)

Parameters

enumType
Type: System.Type
An enumeration type.

Return Value

Type: System.Array
An array that contains the values of the constants in enumType. The elements of the array are sorted by the binary values of the enumeration constants.

ExceptionCondition
ArgumentNullException

enumType is null.

ArgumentException

enumType is not an Enum.

The elements of the array are sorted by the binary values of the enumeration constants (that is, by their unsigned magnitude).

The following example illustrates the use of the GetValues method.


using System;

public class Example
{
   enum Colors { Red, Green, Blue, Yellow };
   enum Styles { Plaid = 0, Striped = 23, Tartan = 65, Corduroy = 78 };

   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {

      outputBlock.Text += "The values of the Colors Enum are:" + "\n";
      foreach (int i in Enum.GetValues(typeof(Colors)))
         outputBlock.Text += i + "\n";

      outputBlock.Text += "\n";

      outputBlock.Text += "The values of the Styles Enum are:" + "\n";
      foreach (int i in Enum.GetValues(typeof(Styles)))
         outputBlock.Text += i + "\n";
   }
}


Silverlight

Supported in: 5

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

Community Additions

ADD
Show:
© 2014 Microsoft