asp.net mvc doubt with the conditional if with keys and without keys "{...}"

1

I have a question about what moments or parts of the code you can use a conditional if or another that can be written without the keys { ... } .

For what I read this will depend on the amount of code that contains that conditional example: if it has a single line would be valid to use it without keys if n lines should be used with keys to enclose the block to execute?

Will it be like this or am I wrong?

    
asked by vcasas 09.05.2018 в 17:13
source

1 answer

1

you're right To use an if without keys only works in the following way:

if("algo")
 //accion que va a realizar

Because if you do this otherwise:

if("algo")
 //Acción a realizar
 //Acción que ya no toma en cuenta

What follows after the declaration of the if takes only the following line, the second line in which case it no longer takes it inside the if, for the second example you need the keys instead, something like this:

if("algo"){
  //Todo lo de aquí lo toma en cuenta
  //y esto
  // y así sucesivamente
}

To my taste it is to make code more elegant, although if you use keys and only want to take into account a line it is also valid:

if("algo"){
   //Acción en una sola linea
}
    
answered by 09.05.2018 / 17:19
source