C
C#8mo ago
stubby

❔ why does it say this variable is undeclared?

No description
14 Replies
stubby
stubby8mo ago
No description
stubby
stubby8mo ago
more normal screenshot
reflectronic
reflectronic8mo ago
they are called roe and colum not row and column
stubby
stubby8mo ago
for some reason my variables in my return statement are undeclared yeah i know but i remade them in the function method idk
stubby
stubby8mo ago
No description
reflectronic
reflectronic8mo ago
right, that is better, because you are actually declaring the variables now, but the problem is that you are declaring them in the wrong place because you declared them inside the try, you can only use them inside of it
stubby
stubby8mo ago
oh ok can i pass it from the try to everything else
reflectronic
reflectronic8mo ago
you would need to move them outside, next to your string roe; to use them from the return
stubby
stubby8mo ago
because if i declare outside, my code doesnt work the way i want it to
reflectronic
reflectronic8mo ago
int row;
int column;

while (true)
{
string roe = Console.ReadLine();
string colum = Console.ReadLine();
// …
try
{
row = int.Parse(roe);
// …
}
}

return (row, column);
int row;
int column;

while (true)
{
string roe = Console.ReadLine();
string colum = Console.ReadLine();
// …
try
{
row = int.Parse(roe);
// …
}
}

return (row, column);
stubby
stubby8mo ago
ok i will try that now thanks for helping @reflectronic the code stops running at row = int.Parse(roe); like the try fails and moves onto the catch i got it to work its fine THANKS
Tvde1
Tvde18mo ago
Also doesn't work as the variables are declared but don't have a value. What if you set a break point, and change while(true) into while(false)? Then the strings don't have a value and return is impossible Or is this incorrect for ints?
reflectronic
reflectronic8mo ago
if you change the code then the code needs to be recompiled and it becomes an error as the code is written it is guaranteed that they are assigned if the code breaks out of the while loop, which is all that matters
Accord
Accord8mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.