Tuesday, September 7, 2010

Comments in C#

The programming language C# supports 3 types of comments:
Single line comments, multi line comments and documentation comments.
Single line comments are introduced by the symbol // and stretch till the end of the current line:

namespace ConsoleApplication1 // this is a single line comment 

Multi line comments stretch between the symbols /* and */ and can thus stretch over multiple lines:

/* This is a comment,
* which stretches over multiple
* lines. */

Finally there are documentation comments, which are started by the symbol ///.
Actually they are a topic for themselves and do not belong to the actual code comments, since they have a XML structure and are used for an automatic code commentation.
Documentation comments are put in front the actual object they are supposed to comment, the development environment automatically adds some tags then.
I do not want to go deeper in this topic, but just give an example how the main function could be commented like:

/// <summary>
/// main function of the program
/// <summary>
/// <param name="args">commandline arguments the program was called with<param>

No comments:

Post a Comment