Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quickly commenting /* selected C# code */ in Visual Studio (not the // whole line)

Visual Studio has a toolbar button/keyboard shortcut/menu item that comments out selected lines of C# code using //.

Is there an equivalent that comments out just the selected code using /* ... */?

e.g.

Given this code

string s = "hello";
Console.WriteLine(s + " world");

If you select + "world" and hit Ctrl+K, Ctrl+C then you end up with

string s = "hello";
//Console.WriteLine(s + " world");

However, I would like

string s = "hello";
Console.WriteLine(s /*+ " world"*/);

This would be useful for when I am making some experimental and temporary amendements to an existing codebase whilst fixing a few bugs.

like image 289
Richard Ev Avatar asked Aug 24 '12 08:08

Richard Ev


People also ask

How do you get uncomment codes quickly?

If you select a block of code and use the key sequence Ctrl+K+C, you'll comment out the section of code. Ctrl+K+U will uncomment the code.

What is the shortcut key to comment multiple lines?

Press Ctrl + C .


1 Answers

Resharper does that. It costs money - but it is worth it.

It's called "Block Comment".

And the default keyboard shortcut is Ctrl+Shift+/

like image 56
James Avatar answered Oct 14 '22 05:10

James