Hello,
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[]')?
Hello,
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[]')?
Assuming your ReadAll
method has a signature like this
string ReadAll(string inputFile);
then the problem is not with inputFile
but with the return value of the method which cannot be assigned to a string[]
.
Are you maybe looking for File.ReadAllLines?
string[] values = File.ReadAllLines(inputFile);
Or do you want to split a string by some delimeter?
string[] values = ReadAll(inputFile).Split('\n');
Based on the exception message you gave us, ReadAll(inputFile)
returns a string
, and you assign it to a string[]
, so that's why it doesn't work.
This would work:
string input = ReadAll(inputFile);
After this do you want to split the strings in some way? We'd need more details to help you further.