This is more of conceptual question, since I am new to C# trying to get a simplified understanding.
My is trying to read lines from text file, which works fine but I am trying to implement following solution to read the last line as well but it gives following error :
Error 1 'System.Collections.Generic.IEnumerable' does not contain a definition for 'Last' and no extension method 'Last' accepting a first argument of type 'System.Collections.Generic.IEnumerable' could be found (are you missing a using directive or an assembly reference?)
Code:
using System;
using System.IO;
using System.Collections;
class Program
{
public static void Main()
{
int counter = 0;
string line;
string xml_files;
// string jpg_files;
System.IO.StreamReader file = new System.IO.StreamReader(@"C:\test\logfile_c#.txt");
string lastLine = File.ReadLines(@"C:\test\logfile_c#.txt").Last();
while ((line = file.ReadLine()) != null)
{
Console.WriteLine(line);
Console.WriteLine(counter);
Console.Read();
counter++;
}
}
}
Can someone help me understand better how to avoid this.
Thanks!!