Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,102 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.

Chris Shearon
Chris Shearon
Courses Plus Student 14,369 Points

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.