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
.
精彩评论