Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8656477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:17:05+00:00 2026-06-12T15:17:05+00:00

In Visual Studio using C# (this happens for me in both 2010 and 2012),

  • 0

In Visual Studio using C# (this happens for me in both 2010 and 2012), I get a weird auto-indent if I enter a new line before an else statement:

if (condition1)
{
    DoSomething();
} // press Enter here, after the brace
    // auto indents to here

    // Helpful comment here about condition2, but awkwardly auto-indented
else if (condition2)
{
    DoSomethingElse();
}

Intuitively, I would expect it to only auto-indent to the same column as the if/else, but it instead goes one indent-level further.

I realize it’s illegal to put other code in between those two blocks anyhow, but I’d still like to put comments there. Does anyone know why this happens or how to fix it? It’s so incredibly weird and annoying to have to hit backspace 4 times whenever I try to comment an else block.

I know someone’s going to say “just put the comment inside the else/if block”, but I’m interested in an actual explanation/solution of/to this phenomenon; furthermore, it doesn’t make sense to me to have a comment explaining code that happened two lines ago.

I also know someone’s going to say “just put the comment on the same line as the else/if block”, but putting comments and code on the same line seems yucky to me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T15:17:06+00:00Added an answer on June 12, 2026 at 3:17 pm

    I just tried this in Visual Studio 2012:

    Indeed, when you write the comment, it doesn’t seem correctly indented.

    But after pressing CTRL + E, CTRL + D, everything is automatically indented correctly (in my opinion):

            if (condition)
            {
    
            }
            // comment line
            // another one
            else if (condition)
            {
    
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was deploying an Azure instance using Visual Studio (2010) and i get this:
I have compiled this using Visual Studio 2010 compiler and it has compiler error
I'm using Visual Studio 2012 for Windows Phone 7 and this is my first
I wrote this simple C code and compiled it using Visual Studio 2010, with
I am using Visual Studio 2010 and C# and try to get my progressbar
I have deployed this application using Visual Studio 2010's Publish feature; it needs to
Visual Studio C++ 2008 I am using this code. However, gethostbyname always returns an
I have a Windows 7 machine with Visual Studio 2005 SP1 installed. Using this,
I am using visual studio 2005 for c++ this summer, but I am still
Sometimes when using Visual Studio it displays a prompt with a filename: This file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.