0

Possible Duplicate:
Do you use curly braces for additional scoping?

I just noticed something and I know this is normal behaviour, but I don't quite understand why. I think I remember learning about this somewhere but I'm not sure.

Braces surrounding CSharp code

The only reason I can think of that you would write code this way is to section-off or split up large sections of code within a single method. But is this the only reason you would use braces this way?

And what is it that allows this code to execute with the surrounding braces which have no method name or identifier associated with them?

I'm also interested in your opinion on this, and would like to know if you write code this way, and why?

Community
  • 1
  • 1
Arrow
  • 2,306
  • 8
  • 35
  • 59
  • Also possible dupe of http://stackoverflow.com/questions/241088/what-do-curly-braces-by-themselves-mean-in-java and http://stackoverflow.com/questions/3189366/is-it-wrong-to-use-braces-for-variable-scope-purposes – Tim S. Oct 19 '12 at 01:38
  • 2
    In short, I'd call it a code smell - if you have a method that such a grouping would be very useful, you're probably better off refactoring the code so that you don't. – Tim S. Oct 19 '12 at 01:39
  • Thanks @TimS. for posting those links, I didn't even realise they were related. – Arrow Oct 19 '12 at 01:52

0 Answers0