I know that when using the IEnumerable returned by File.ReadLines() in a foreach loop, the file gets closed automatically after the loop.
I just need to quickly check the first line of a file. Is this enough or will it keep the file open?
protected void Append(string filePath, Encoding encoding)
{
try
{
string firstLine = File.ReadLines(filePath, encoding).First();
// more code here
}
catch
{
// more code here
}
}