Hello
I am trying to get the last lines value in a text file and display it
on screen / read it into a variable.
When I run the following code in a console I get the
following error
"Use of unassigned local variable "LastLine"
What is the problem?
using System;
namespace ConsoleApplication4
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
int counter = 0;
string line;
string LastLine;
System.IO.StreamReader file = new
System.IO.StreamReader("c:\\test.txt");
while((line = file.ReadLine()) != null)
{
Console.WriteLine (line);
LastLine = line;
counter++;
}
file.Close();
Console.WriteLine (LastLine);
Console.ReadLine();
}
}
}