this is my code:
var info;
int n = int.Parse(Console.ReadLine());
for (int a = 0; a < n; a++)
{
string input = Console.ReadLine();
List<string> inputs = input.Split(" ").ToList();
info = new Employee(inputs[0], double.Parse(inputs[1]), inputs[2], inputs[3], inputs[4], int.Parse(inputs[5]));
}
Console.WriteLine(info.ToString());
I have to declare the variable info
before the loop. The problem is that the declaring object(i dont' know how to call it)info = new Employee(inputs[0], double.Parse(inputs[1]), inputs[2], inputs[3], inputs[4], int.Parse(inputs[5]));
variable is not var
and the var info
is highlighted by the program as a mistake. i have to change the var
behind info
with another variable.
Edit:
Employee info;
int n = int.Parse(Console.ReadLine());
for (int a = 0; a < n; a++)
{
string input = Console.ReadLine();
List<string> inputs = input.Split(" ").ToList();
info = new Employee(inputs[0], double.Parse(inputs[1]), inputs[2], inputs[3], inputs[4], int.Parse(inputs[5]));
}
Console.WriteLine(info.ToString());
now that I changed the var
with Employee
as one of the comments suggested, i get another error in this line Console.WriteLine(info.ToString());
. It highlights the info
as a mistake. "Error CS0165 Use of unassigned local variable 'info'".