Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# C# Basics (Retired) Console I/O Namespaces

Samuel Fortunato
Samuel Fortunato
20,229 Points

Do I have to format the curly braces this way in C#?

In the video, the teacher is formatting the curly braces like this:

namespace Name
{
  class ClassName
  {
    // etc.
  }
}

I find this annoying, as I've been learning programming languages (such as JavaScript) that would format the curly braces like this:

namespace Name {
  class ClassName {
    // etc.
  }
}

Is it necessary? Is this just convention? Will I upset people at possible jobs/teams if I write my curly braces the second way? Thank you.

1 Answer

Stuart Wright
Stuart Wright
41,118 Points

This is a matter of style. Choose whichever you prefer for studying and personal projects (I prefer your way too).

But if you find yourself working in a team in future, they will likely have their own style guidelines which you should follow, regardless of personal preference. The examples in the official docs use the same version as in the video, so I suspect this is more common for C#.

Edit to add: chances are if you get a job using C# that you'll be using an IDE such as Visual Studio, which I'm pretty sure can automatically format your code for you. So you can write the code in your preferred style, then click a button to convert it to the team's preferred style.

Agreed. I've been in Java for a few years now and much prefer the opening bracket on the same line. The standard C# way seems to have it on new lines. Glad I found the option in Visual Studio to "fix" that.