Click here to Skip to main content
Click here to Skip to main content

Commenting/uncommenting segments easily in C#

By , 24 Jan 2011
Rate this:
Please Sign up or sign in to vote.
You're probably already aware of the two popular types of ways to comment-out text in your code:
1. Single line comment with the double right-slash:
// this is an example of a single line of comment
2. Commenting out an entire segment with the opening /* and the closing */:
/*
int intValueA = 12;
int intValueB = 234;
int intSum = intValueA + intValueB;
*/
and you've probably commented out an entire segment with no regard for the single line comments tucked within:
/*
// set first value
int intValueA = 12;
// set second value
int intValueB = 234;
// calculate sum
int intSum = intValueA + intValueB;
*/
but have you ever considered commenting out the opening/closing comments? "why would I do that?" you may ask.
///*
// set first value
int intValueA = 12;
// set second value
int intValueB = 234;
// calculate sum
int intSum = intValueA + intValueB;
//*/
 
Of course when you comment out the opening-comment slash-asterisk, then that segment of code is no-longer commented out and by commenting out the closing asterisk-slash combination, it is ignored whenever the segment is not commented it and it still terminates the segment if the opening is not commented.
In other words, by doing this, you can easily comment/uncomment the entire segment by uncommenting/commenting the opening comment.
 
/*  <- single line commenting this line 'uncomments' the entire segment!
// set first value
int intValueA = 12;
// set second value
int intValueB = 234;
// calculate sum
int intSum = intValueA + intValueB;
//*/

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Christ Kennedy
CEO unemployable
Canada Canada
Christ Kennedy, published his fourth novel "Cleats of the Counter Revolution" in the summer of 2010. He grew up in the suburbs of Montreal and is a bilingual Quebecois with a bachelor’s degree in computer engineering from McGill University and is currently walking across ontario plotting a new novel, far away from any computer.

Comments and Discussions

 
GeneralMy vote of 5 PinmemberPIEBALDconsult13-Aug-12 18:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 24 Jan 2011
Article Copyright 2011 by Christ Kennedy
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid