Enum.GetValues() Return Type

You need to cast the result to the actual array type you want

(Response[])Enum.GetValues(typeof(Response))

as GetValues isn't strongly typed

EDIT: just re-read the answer. You need to explicitly cast each enum value to the underlying type, as GetValues returns an array of the actual enum type rather than the base type. Enum.GetUnderlyingType could help with this.


If you're using NET 3.5 (i.e. you have LINQ) you can do:

var responses = Enum.GetValues(typeof(Response)).Cast<Response>();

Tags:

C#

Enums