Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 852
AngryHacker Avatar asked Aug 27 '26 15:08

AngryHacker


1 Answers

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 restore format
like image 196
coder_b Avatar answered Aug 30 '26 04:08

coder_b



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!