I am a newbie and trying to get back in the programming game. Sorry for my ignorance and lack of knowledge as well.
I am trying to see how to fix the return type error message in the code below. I know I can define the variable outside the try block with explicit data type but can that be done for 'var' or any other suggestions.
private IEnumerable GetDirFiles(String location)
{
try
{
//Search all directories for txt files
var emailfiles = Directory.EnumerateFiles(location, "*.txt", SearchOption.AllDirectories);
}
catch(Exception ex)
{
Console.WriteLine("Message for admins: " + ex.Message);
}
finally
{
textBox1.Clear();
var emailfiles = Directory.EnumerateFiles(location, "*.msg", SearchOption.AllDirectories);
}
return emailfiles;
}
The error message is "emailfiles does not exist in the current context" which I understand as to why because it is being defined in the try block.
Thanks.