To use the variable outside the block you need to declare it outside the block.
As the variable has to have a value even if you don’t run the code in the block, you either have to set an initial value:
string test = null;
if (condition) {
test = "success";
}
or use an else
block to set a value otherwise:
string test;
if (condition) {
test = "success";
} else {
test = null;
}
solved Can’t use nested variable