0

In C#, variable decleared in side try block is local variable or something else.

I have tried to get input under a try block and use it outside. But It throws error in sololearn compilar.

9th Jul 2025, 5:28 AM
Ahnaf Tahmid Enan
Ahnaf Tahmid Enan - avatar
2 Answers
+ 4
show us your code. instead of try-catch, a simpler way is to use TryParse methods if you're doing conversions.
9th Jul 2025, 6:00 AM
Bob_Li
Bob_Li - avatar
0
You need to instance the variable outside the try then you will be able to return it, if everything works, other hand you will get the catch block where you need to handle the variable like setting up as null or something, or just throw;
1st Oct 2025, 8:03 AM
Code With Lovelace
Code With Lovelace - avatar