Every computer language implements the concept of "scope" which is the
execution context in which actions will be executed, and the context (namespace context) in which "objects" (variables, classes, etc.) exist, and are accessible. The semantics of how they do this vary widely.
In C#, an
if statement defines the start of a logical "block" which consists of the code to be executed if the evaluation of the conditional expression results in the boolean value 'true.
The braces that enclose code to be executed define execution scope.
Whether you write:
if(condition)
{
}
if(condition){
}
Is a matter of style, and convention [
^]. It's also a matter of great meaning to some people who engage in almost "religious" wars over the formatting of curly braces, whether or not using tabs or spaces is better [
^], etc.
C# allows you to omit the enclosing braces that define a logical block of code
only in the case you wish to execute a single code statement.
People disagree about whether allowing a no-braces-enclosed special syntax for the case of a single statement is a "good thing."
I am among those who think it is not a "good thing," and that it's a very good idea to get in the habit of always using braces, and that this practice, in the long-run, will lead to more readable, and maintainable code, as well as helping one avoid trivial errors.
C# also allows you to use the "?:" pair of delimiters as a special if/then/else "short-cut:" [
^]. I find that useful in certain cases.