if(){
String var=1;
if(var==-1){
//do this
}
else
{
if()
{
String myString=var; //This is where I want to use var
}
}
}
Now myString is not getting assigned the value of var..why is that ? It’s nested if..it should get the value..isn’t it ?
Following code seems to work fine:
Variable and Method Scope in Microsoft .NET is a good reference to understand how scoping
works.
Btw,
varis a type used in 3.5 and above; should avoid naming variables akin to type names.