Using Comments C# Help

The next topic – adding comments to your code -looks very simple on the surface but can be complex .

Internal Comments within the Source Files

As noted earlier in this chapter, C# uses the traditional C-type single-line and multiline comments.

Everything in a single-line comment, from the // to the end of the line, will be ignored by the compiler, and everything from an opening /* to the next */ in a multiline comment combination will be ignored. Obviously’, you can’t include the combination */ in any multiline comments, because this will be treated as the end of the comment.

It is actually possible to put multiline comments within a line of code:

Console.WriteLine(/* Here’s a comment! */* ‘This will compile.’);

Use inline comments with care because they can make code hard to read. However; they can be useful when debugging if, say, you temporarily want to try running the code with a different value somewhere:

DoSomething(Width, I*Height*| 100);

Comment characters included in string literals are, of course, treated like normal characters: