作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我收到错误:
'string[]' does not contain a definition for 'Cast' and no extension method 'Cast' accepting a first argument of type 'string[]' could be found (are you missing a using directive or an assembly reference?)
在下面的代码中:
return mNames.Cast().ToArray();
我需要什么 using 指令或程序集引用?我如何找出这些东西?
我是 C# 和 .NET 的菜鸟,我只是复制代码来完成工作,所以不要对我太技术化。
最佳答案
(1) 确保您使用的是 C# 3.0+
(2) 确保您的代码包含:
using System.Linq;
(3) .Cast
是一个泛型方法,需要指定类型参数,像这样:
return mNames.Cast<AnotherType>().ToArray();
关于c# - '字符串[]' does not contain a definition for '类型转换',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11222256/
我是一名优秀的程序员,十分优秀!