C
C#14mo ago
stubby

❔ why does it say this variable is undeclared?

No description
14 Replies
stubby
stubbyOP14mo ago
No description
stubby
stubbyOP14mo ago
more normal screenshot
reflectronic
reflectronic14mo ago
they are called roe and colum not row and column
stubby
stubbyOP14mo 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
stubbyOP14mo ago
No description
reflectronic
reflectronic14mo 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
stubbyOP14mo ago
oh ok can i pass it from the try to everything else
reflectronic
reflectronic14mo ago
you would need to move them outside, next to your string roe; to use them from the return
stubby
stubbyOP14mo ago
because if i declare outside, my code doesnt work the way i want it to
reflectronic
reflectronic14mo 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
stubbyOP14mo 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
Tvde114mo 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
reflectronic14mo 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
Accord14mo 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.
Want results from more Discord servers?
Add your server