#29 – Comments

Comments in a C# program denote text that is ignored by the compiler and therefore has no effect on the behavior of the program.

There are two types of comments in C#:

  • Single line comments:  start with //, extend to end of line
  • Delimited comments:  surrounded by /*  */, can span multiple lines

Examples:

 string s1 = "Hi";        // This is a single-line comment

 /*  Multiple line
  *  comment.  Nice convention to use
  *  asterisk at the start of each line. */

 string s2 = "/* This is a string, rather than a comment */";
 string s3 = "// same here";

 // Nested comments /* ignored */

 //--------------------------------------
 // Even better style for block comment
 //--------------------------------------

More

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

2 Responses to #29 – Comments

  1. Jorge Luis says:

    In fact Sean, comments are ignored by the compiler and therefore has no effect on the behavior of the program.

    But they are so important for programmers. Taking 15 minutes to comment out your program, could save you 1 hour of headaches.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 43 other followers