I am writing the following program in which I have to access variable "lat" outside the if statements. But compiler is showing me an error while using this statement.
int LAC = Convert.ToInt32(lat[0], 16);
The error I am getting is:
The name lat does not exist in current context
What can be the possible reason for this? As I am using a string initialized inside an if loop, outside the if loop. Also if I would have declared it local to some function, this error would have been justified but when used inside a loop and then being used outside the loop its showing error. What can be the reason? The code is as follows:
flag = string.Compare(excel_getValue("A" + i), "DATE");
if (flag == 1)
{
string[] date = excel_getValue("A" + i).Split();
}
else if (flag != 1)
{
string[] lat = excel_getValue("A" + i).Split();
}
if (result == 0)
{
MessageBox.Show("Location Tracking Complete");
// Environment.Exit(0); // program exit
Thread.Sleep(5000);
}
int LAC = Convert.ToInt32(lat[0], 16); // Converting to int
latshould be used if flag==1? you declare it and set its value only in one conditionflag = string.Compare(excel_getValue("A" + i), "DATE");that's the statement that decide flag value.