sl3dg3
sl3dg3

Reputation: 5180

System.Enum.GetValues: In C# not the same as in VB?

Im trying to convert following line of VB.NET to C#:

Dim langs As New List(Of LanguageEnum)(System.Enum.GetValues(GetType(LanguageEnum)))

I ended up with the following translation, which does not work:

List<LanguageEnum> langs = new List<LanguageEnum>(System.Enum.GetValues(typeof(LanguageEnum)));

--> "The best overloaded method match {...} has some invalid arguments." Even http://www.developerfusion.com/tools/convert/vb-to-csharp/ would give me exactly this translation. What is wrong about it?

Upvotes: 3

Views: 2142

Answers (1)

onof
onof

Reputation: 17367

You have to cast it:

List<LanguageEnum> langs = new List<LanguageEnum>((LanguageEnum[]) System.Enum.GetValues(typeof(LanguageEnum)));

In fact, Enum.GetValues returns an Array.

Upvotes: 6

Related Questions