c# - About using variable inside of nested if -


  if () {string var = 1; If (var == - 1) {// do this} and {if () {String myString = var; // this is where i want to use var}}}  

Now merrystring is not being given the value of hostile ... why is it? It's a nest if ... he should get the price..Isn't it?

The following code works fine:

  If (true ) {String var = "1"; If (var == "-1") {/ * DoSomething () * /} and {if (true) {string myString = var; // gives 1 in myString! MessageBox.Show (myString); }}}  

It is a good reference to understand how the scoping works

BTW, one type 3.5 and above is used; Naming names of hostile names should be avoided.


Comments