Blog Stats
  • Posts - 24
  • Articles - 0
  • Comments - 72
  • Trackbacks - 91

 

Use C# comment styles to your advantage

Comments within a C# method body tend to A) make a problem statement then B) document the steps to solve the problem.  The problem statements tend to be multi-line; the details of the solution tend to be single-line. 

I want the problem statements to stand out.  Traditionally I use #region blocks to group the problems.  Unfortunately, regions are single-line.  They are also slightly more laborous to construct.

Lately I have been using a triple-slash comment block at the top of the method body to state the problem:

/// <summary>
/// Occurs when the page loads.
/// </summary>
private void Page_Load(object sender, System.EventArgs e)
{
    /// Configure the http response to return a correct set of
    /// cache headers. Validation headers must also be returned.

    // set the etag
    this.Response.Cache.SetETag("055aba934a3c21:380");

    // set the cache policy
    this.Response.Cache.SetCacheability(HttpCacheability.Public);
}

Another reason to use the triple-slash comment block within a method body, as opposed to the <remarks> block,  is that it does not form a part of the API documentation.  That is, the client-supplier relationship plays a role here.  It is desirable to separate interface documentation from implementation documentation - they are intended for two different audiences. For a given method the external documentation should be placed in a <remarks> block above the method declaration; the internal documentation should be placed in triple-comment blocks at the top of the method body.  It will naturally stand out from the implementation specifics. 

This approach works better than using /* */-style comments blocks because such comments cannot be nested.

Incidentally, VS.NET has a handy button on the Text Editor toolbar to comment out the selected lines.  It adds double-slash comments at the extreme left side.  A complementary button exists that will uncomment the selected lines.  It seems that left-justified comments are reserved for commenting-out code, not documentation.


Feedback

# re: Use C# comment styles to your advantage

Gravatar good idea 11/19/2004 1:05 PM | Brad

# re: Use C# comment styles to your advantage

Gravatar
不锈钢管
无缝钢管 12/11/2007 2:41 AM | bsknuisss

# re: Use C# comment styles to your advantage

Gravatar I like /* */-style 1/6/2008 6:27 AM | intranet

# re: Use C# comment styles to your advantage

Gravatar I like you ideas and enjoy your news letter but frankly i find you to be an asshole. Last night at dinner when you got mad at my wife and hit her in the teeth was completely unnacceptable. All she said was she didnt like your tie. I mean jesus christ. It was a big deal! At least she is used to getting bopped everyonce in a while! See at christmas brosef 6/3/2009 11:32 PM | tosha

# re: Use C# comment styles to your advantage

Gravatar 8.18Cwow power leveling 8/17/2009 9:30 PM | wow

# re: Use C# comment styles to your advantage

Gravatar
Nice article, very helpful.
Thanks!!

nike air
9/7/2009 8:18 AM | klecike

# re: 3M Half Marathon

Gravatar That Post is Full of informative. Thanks for that kind of sharing. Hope u will again share with us. 3/14/2011 10:49 PM | discount gucci handbags

# re: Use C# comment styles to your advantage

Gravatar I have found it really useful. 3/31/2011 1:48 AM | truereligionwest

# re: Use C# comment styles to your advantage

Gravatar thanks for the news
karen millen dresses 4/23/2011 4:43 AM | karen millen dresses

# re: Use C# comment styles to your advantage

Gravatar Thanks for sharing this great piece of information. Do keep us update with some more updates. I love your blog very much. Finding something like this is very rare! 5/11/2011 4:34 AM | female hair loss

# re: Use C# comment styles to your advantage

Gravatar Thanks for posting this,. 6/28/2011 8:48 AM | Rockwool Insulation

# re: Use C# comment styles to your advantage

Gravatar Thanks for posting this,. its really nice post thanks again 6/28/2011 8:49 AM | Rockwool Insulation

# re: Use C# comment styles to your advantage

Gravatar I recently tried to use your flash app, the package throws an exception on installation under Umbraco 4. The files are imported, but when I get to step 5 there is no Gallery Example node.

I have read a few of the articles on your website now, and I really like your style of blogging 7/8/2011 8:26 PM | gucci outlet online

# Nice share.

Gravatar Researching new phosphor materials (which are currently being used in fluorescent lighting as well) that make LED light “warmer”[url=http://www.sino-buy.com/index.php?route=product/product&path=68&product_id=409]Outdoor LED Flood Lights[/url] 7/16/2011 12:40 AM | Outdoor LED Flood Lights

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

 

 

Copyright © Eron Wright