-1

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[]')?

Nathan Campos
  • 28,769
  • 59
  • 194
  • 300

2 Answers2

6

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');
dtb
  • 213,145
  • 36
  • 401
  • 431
1

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.

Meta-Knight
  • 17,626
  • 1
  • 48
  • 58