#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

Advertisement

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

3 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.

  2. kai zhou says:

    There’s another important comment type: the XML documentation for C# source codes.
    ///
    ///
    ///
    ///…

    One more thing, comments are good and necessary, but sometimes a lot of comments may mean a low quality of source codes. High quality source codes do not need or need very little comments to explain what it does and how it does.
    Anyway, comments are good things then none.

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

%d bloggers like this: