简体   繁体   中英

How to prevent Visual Studio from formatting specific code?

I type the code below:

if (rows == 0) break;

and when I add the semicolon at the end, VS springs into action and converts it to:

if (rows == 0) 
    break;

Same thing happens with if (rows = 0) return; and some other constructs.

How can I prevent VS from formatting this specific code interaction without messing with all the other niceties that it provides? I looked in Tools/Options/Text Editor/C#/Code Style/Formatting, but don't see anything obvious.

You can enable the VS option in main menu:

Tools > Options > Text Editor > C# > Code style > Formatting > Wrapping >

Leave statements and member declarations on the same line

在此处输入图像描述

English version of same options dialog (VS2017 version):

在此处输入图像描述

you add pragam waning disable settings, so when you do Ctr+K+D it will not format or whatever shortcut keys you may be using to format.

#pragma warning disable format
public class Item
{
      public string Prop1 { get; set; } 
    public string Prop2 { get; set; }
} 
#pragma warning disable format

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM