开发者

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

开发者 https://www.devze.com 2023-02-12 22:15 出处:网络
Im trying to convert following line of VB.NET to C#: Dim langs As New List(Of LanguageEnum)(System.Enum.GetValues(GetType(LanguageEnum)))

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 abou开发者_C百科t it?


You have to cast it:

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

In fact, Enum.GetValues returns an Array.

0

精彩评论

暂无评论...
验证码 换一张
取 消