Single-Line Comments

A single-line comment starts with two consecutive forward slashes and stretches until the end of the source line. You’ve seen numerous examples of this style already:

// Badvar mystery = GetSomething();  // what's the return type of GetSomething?var x = 2159940436;            // answer immediately: int or long?

As you can see, the comment doesn’t necessarily need to stand on its own in a line of code; it can also be used just at the end of a line after some meaningful source code. But it can’t be used in the middle of a line of code because there’s no way to terminate the run of comment text.

This style of commenting has a technical advantage: There are no worries about nesting of comments, which, ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.