字符串数组和字符串参数
我正在开发一个简单的应用程序,其中有这样一行:
string[] values = ReadAll(inputFile);
As inputFile is a string, but how I can do this withoutconflications(Cannot implicitly conversion type 'string' in 'string[]')?
I"m developing a simple application that have a line like this:
string[] values = ReadAll(inputFile);
As inputFile is a string, but how I can do this without conflicts(Cannot implicitly convert type 'string' in 'string[]')?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您的 ReadAll 方法具有这样的签名,
那么问题不在于 inputFile ,而在于该方法的返回值无法分配给 string[] 。
您是否正在寻找 File.ReadAllLines?
或者您想要按某个定界符分割字符串?
Assuming your
ReadAll
method has a signature like thisthen the problem is not with
inputFile
but with the return value of the method which cannot be assigned to astring[]
.Are you maybe looking for File.ReadAllLines?
Or do you want to split a string by some delimeter?
根据您给我们的异常消息,
ReadAll(inputFile)
返回一个string
,然后将其分配给string[]
,所以这就是为什么它不起作用。这可行:
之后你想以某种方式分割字符串吗?我们需要更多详细信息来为您提供进一步帮助。
Based on the exception message you gave us,
ReadAll(inputFile)
returns astring
, and you assign it to astring[]
, so that's why it doesn't work.This would work:
After this do you want to split the strings in some way? We'd need more details to help you further.