I'm developing an application and I'm creating a method that has to read a file, but I'm not sure how to return a message in case that the file doesn't exist because my method return an array
Here is what I have:
MyFile = "C:\\MyFile.txt";
private string[] LoadFile()
{
string Lines[];
if (! File.Exist(MyFile))
//????? <- return a message here!!
else
Lines = File.ReadAllLines(MyFile);
return Lines;
}
I was thinking to do this, is the best way to do it?
private string[] LoadFile()
{
string Lines[];
if (! File.Exist(MyFile))
{
Lines[] = new string[1];
Lines[0] = "File Not Exist";
}
else
Lines = File.ReadAllLines(MyFile);
return Lines;
}
Then catch the error message and print it?
What is the best way to that validation?