Guidelines for Curly Braces in C#

Problem
You want to know where to place curly braces when defining a block of C# code.

Solution
Open and close curly braces on a line of their own.

Comments
Some folks like to use the C convention of placing open curly braces on the same line as the statement that defines the block. This style is fine as long as everyone working on the code consistently applies it. It’s a matter of preference that’s typically a choice between code readability and conciseness. I choose readability.

Example

// This style enhances readability.
void DoSomething(int x)
{
    if ( x == 0 )
    {
        ...
    }
    else
    {
        ...
    }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s