Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2015 Curly Brace Formatting: If, Else If, Else

I recently upgraded to Visual Studio 2015 (update 1) and have been getting things configured as I want them to be, however I am having a little trouble with formatting with regards to curly braces! I am under the assumption that the 2nd code sample is the more accepted convention, yet I can not seem to get my settings right. What am I doing wrong here?

Visual Studio is currently auto-formatting my code like this, notice the else {

    public static string Gender(string x)
    {
        if (x == "M")
        {
            return "Male";
        }
        else if (x == "F")
        {
            return "Female";
        }
        else {
            return "Unknown";
        }
    }

I would like my code to be auto-formatted like this

    public static string Gender(string x)
    {
        if (x == "M")
        {
            return "Male";
        }
        else if (x == "F")
        {
            return "Female";
        }
        else
        {
            return "Unknown";
        }
    }
like image 984
GTRocker8824 Avatar asked Nov 08 '22 22:11

GTRocker8824


1 Answers

I have Visual Studio 2015 Update 1 and have it set up to format like in your second code snippet.

An important setting is to uncheck "place else on new line" option.

If this is not enough, I am posting a screenshot with all my settings (http://imgur.com/XPvH8pI)

enter image description here

like image 150
George Avatar answered Nov 15 '22 12:11

George