gpt4 book ai didi

c# - '字符串[]' does not contain a definition for '类型转换'

转载 作者:太空狗 更新时间:2023-10-29 18:02:24 26 4
gpt4 key购买 nike

我收到错误:

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com