12

When i try to comment out some highlighted text (Using the Comment Button at the top of the menu) in C# using Visual Studio 2012, then it comments out the whole line with double slashes. But when i use C++ in the same IDE, then it only comments out the highlighted text, using /* */

Is there VS command/shortcut/button that comments selected text (part of the line) with /*...*/ in C# also?

enter image description here

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
Assassinbeast
  • 1,207
  • 1
  • 17
  • 33
  • 1
    are you asking if C# can use both comments? or are you asking if *Visual Studio* will *automatically* create such comments for you? – Michael Edenfield Oct 16 '13 at 16:24
  • 1
    For clarification, I believe @Assassinbeast is asking how to leverage Visual Studio to automatically comment in C# LIKE it does in C++. – Bob2Chiv Oct 16 '13 at 16:24
  • Yes Bob2Chiv, thats what i mean. – Assassinbeast Oct 16 '13 at 16:28
  • After looking a lot, I'm afraid it is not possible. The best solution would be to create an add-in for that. You can also quickly copy/paste your code into, for example, Notepad++ and apply a text macro there and paste it back in VS, but that's really not optimal. – Pierre-Luc Pineault Oct 16 '13 at 16:34
  • @Pierre-LucPineault:- I dont think for commenting a code this would be very optimal. I still suggest that the best could be just shift the comments to the right and may be add some more information in the comments if neccessay. It would be optimal and time saving! Do correct me if I am wrong! – Rahul Tripathi Oct 16 '13 at 16:39
  • @RahulTripathi Creating an extension with keybinding is much more optimal than switching it to the right, and a few hours later asking yourself "Where the hell does that part of text is supposed to go?" – Pierre-Luc Pineault Oct 16 '13 at 16:41
  • @Pierre-LucPineault:- I agree to this. I was asking about this:- *You can also quickly copy/paste your code into, for example, Notepad++ and apply a text macro there and paste it back in VS* – Rahul Tripathi Oct 16 '13 at 16:43
  • @RahulTripathi Oh, that, of course, would indeed be a time waster. – Pierre-Luc Pineault Oct 16 '13 at 16:49
  • @Pierre-LucPineault:- Although I like your idea if key binding extension! :) – Rahul Tripathi Oct 16 '13 at 16:49
  • An alternative would be to copy/paste the line and comment it, and modify the original. To put it back, just delete the whole line and uncomment the next one. Basically, it goes like this : (without any selection) CTRL + C -> CTRL + V -> CTRL + K C -> proceed to your changes. To restore : Shift + Delete -> CTRL + K U. – Pierre-Luc Pineault Oct 16 '13 at 16:52
  • @Pierre-LucPineault:- I have just found a link in which it is mentioned that TEXT MACROS are supported in VS2012 and they have the features of Notepad++. Check my answer. I think that makes sense. Isnt it? – Rahul Tripathi Oct 16 '13 at 16:54
  • Yes, VC# does not do comments like that. There is a suggestion for this here: http://connect.microsoft.com/VisualStudio/feedback/details/797027/visual-studio-comment-out-partial-line In the meantime you can use R# and Ctrl+/ – Peter Ritchie Oct 16 '13 at 16:55

3 Answers3

1

This does not appear to be a setting you can change in Visual Studio. The documentation for the command the description is:

Marks the current line of code as a comment, using the correct comment syntax for the programming language.

So it would appear that the commenting ability is baked into each language config individually (no relevant settings appear under the Text Editor section specific to a language). Looks like it could have been done easily with Macros, but Macros are no long supported in 2012 :( (help bring them back!)

As the linked SO question suggests, a plug-in/add-in could be developed, but I'm guessing its not worth your time unless you do a lot of that kind of commenting :)

Community
  • 1
  • 1
Ocelot20
  • 10,510
  • 11
  • 55
  • 96
0

I dont think there is any shortcut for inline comments. The best I have known is CTRL K + CTRL C but that too comments the whole line.

I think if you have a comment you can instead shift it to the right and then comment it using the usual syntax //

Something like this:-

 int a=500;  //200+

EDIT:-

You can use TEXT MACROS FOR VISUAL STUDIO 2012

You can use it to automate repetitive text editing tasks. It is inspired by the macro feature of Notepad++, so if you have used it then you already know how to use this extension.

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
  • Can you explain how this is possible with that extension? I'm only roughly familiar with Notepad++ macros, but they aren't really programmable like Visual Studio 2010 ones were. Thus, I'm not sure how you would record one that tracks the currently highlighted portion of your code. – Ocelot20 Oct 16 '13 at 18:40
0

I don't think there is any features in Visual Studio in c# environment for that. To do so you have to create macro. or you can also add extensions from this link

else you have to manually comment with /**/

Regon
  • 392
  • 1
  • 4
  • 17