Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
System.Enum.GetValues:在C#中与在VB中不同?_C#_Vb.net - Fatal编程技术网

System.Enum.GetValues:在C#中与在VB中不同?

System.Enum.GetValues:在C#中与在VB中不同?,c#,vb.net,C#,Vb.net,我正在尝试将VB.NET的以下行转换为C#: 我最终得到了以下翻译,但不起作用: List<LanguageEnum> langs = new List<LanguageEnum>(System.Enum.GetValues(typeof(LanguageEnum))); List langs=新列表(System.Enum.GetValues(typeof(LanguageEnum)); -->“最佳重载方法匹配{…}有一些无效参数。” 甚至会给我这个翻译。有什么不

我正在尝试将VB.NET的以下行转换为C#:

我最终得到了以下翻译,但不起作用:

List<LanguageEnum> langs = new List<LanguageEnum>(System.Enum.GetValues(typeof(LanguageEnum)));
List langs=新列表(System.Enum.GetValues(typeof(LanguageEnum));
-->“最佳重载方法匹配{…}有一些无效参数。” 甚至会给我这个翻译。有什么不对吗?

你必须投下它:

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

事实上,
Enum.GetValues
一个
数组

你切割的部分(
{…}
)对我们来说是很有趣的。啊,我明白了:VB在这里做了一些隐式转换。谢谢!
List<LanguageEnum> langs = new List<LanguageEnum>((LanguageEnum[]) System.Enum.GetValues(typeof(LanguageEnum)));