Search code examples
c#arrayswindows-mobile-5.0

String Array And a String Parameter


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


Solution

  • 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');