开发者

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 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜