You are currently viewing [SOLVED] VSCode format curly brackets on the same line c# – check simple solution in 2 mins!
Could You Please Share This Post? I Appreciate It And Thank YOU! :) Have A Nice Day!
4.9
(807)

[ VSCode format curly brackets on the same line c# ] If you work with other programming languages such as Java or Scala, you have probably been pissed off more than once about how the code in C# is formatted by default. Any method / function, if-else block, or other syntax resulted in more than one line causing a brace to appear on an additional line. See the example below:

VSCode format curly brackets on the same line c#

    private void OnTriggerExit(Collider other)
    {
        if (other.gameObject.tag == "Enemy")
        {
            hitByEnemy = true;
        }
    }

Personally, this frustrated me because the code was becoming less and less readable for me. A number of lines of code shot off into space. Personally, I use Prettier – Code formatter, but it defaults to not having that set for C # so that the opening brace is on the same line. I also did not find an option in the configuration of this extension to change it.

Therefore, you need to move to the c # compiler level. Configurations can be applied locally by creating the omnisharp.json file in the main project directory, or applied globally. In this article, we will configure the first option.

VSCode: omnisharp.json

In the project root directory, create a new omnisharp.json file and then enter the following configuration:

{
    "FormattingOptions": {
        "NewLinesForBracesInLambdaExpressionBody": false,
        "NewLinesForBracesInAnonymousMethods": false,
        "NewLinesForBracesInAnonymousTypes": false,
        "NewLinesForBracesInControlBlocks": false,
        "NewLinesForBracesInTypes": false,
        "NewLinesForBracesInMethods": false,
        "NewLinesForBracesInProperties": false,
        "NewLinesForBracesInObjectCollectionArrayInitializers": false,
        "NewLinesForBracesInAccessors": false,
        "NewLineForElse": false,
        "NewLineForCatch": false,
        "NewLineForFinally": false
    }
}

If you do not see the difference in formatting right away, close and restart VSCode. And now I present how the previously presented method looks after applying the new formatting. (VSCode format curly brackets on the same line c#)

Only on such a small method we limited the code by two lines! Think how much less code will take up a line when the class is more complex? 🙂

    private void OnTriggerEnter(Collider other) {
        if (other.gameObject.tag == "Enemy") {
            hitByEnemy = true;
        }
    }

That’s all about topic: VSCode format curly brackets on the same line c#! Enjoy!

Could You Please Share This Post? 
I appreciate It And Thank YOU! :)
Have A Nice Day!

BigData-ETL: image 7YOU MIGHT ALSO LIKE

How useful was this post?

Click on a star to rate it!

Average rating 4.9 / 5. Vote count: 807

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?