-4

On a post on a site I first saw this, previously I only saw it in java. My question is, what is the proper way of writing your curly brackets according to the unspoken rules of programming that everybody always talk about?

Option A :

If( a==b){
//code here
}

Option B:

If(a==b)
{

//code here

}

Are both accepted, or does it just very from person to person. Thank you!

erik.dreyer
  • 17
  • 1
  • 8

2 Answers2

1

C# code conventions do vary a bit from developer to developer and company to company. However, you've asked a very simple question, so I'll try to give you a bit of insight (below). Learn more on MSDN with C# Coding Conventions.

    string a, b, c;
    a = b = c = string.Empty;

    if (a == b)
    {
        //Conventional syntax.
        c = a + b;
    }

    if (a == b)
        // But really, for simple if statements curly braces are not needed.
        c = a + b;

    //Typically you will _not_ see this treatment of curly braces,
    //which is used instead in JavaScript.
    if (a == b) {
        c = a + b;
    }
darlirium
  • 370
  • 4
  • 9
0

Both of them are accepted and you can use with no difference, it's just a matter of user's choice. I normally go with

 If(a==b){

}

to make it easier to track.

user 12321
  • 2,846
  • 1
  • 24
  • 34