Statement-Level Comments in C#

Problem
What about statement-level comments? How should you handle those?

Solution
In general, avoid statement-level comments. One exception may be when you need to explain what a variable or argument does.

Comments
Statement-level comments are those that are on the same line and to the right of code.

Examples

// Incorrect.
while ( doc.Read() )     // Read all records.
{
    ...
}

// Correct.
// Read all records.
while ( doc.Read() )
{
    ...
}

// Correct.
string inputFile;       // Input file.
string outputFile;      // Output file.

// Correct.
void LoginWith(var userName,    // User's username.
    var password                // User's password.
    );

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 )

Google+ photo

You are commenting using your Google+ 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