Ad space (banner)
#๏ธโƒฃC# Lessons
Lesson 17 / 68

Writing Comments

In this lesson you will learn how to write comments in C# so the intent of your code is clear to other people and to your future self. This is for anyone searching for "C# comments syntax".

A comment is a note for humans that has no effect on execution. // starts a single-line comment and /* */ wraps a multi-line one.

The sample code shows all three patterns: a whole-line comment such as // This is a single-line comment, a trailing note as in int price = 100; // product price, and a multi-line comment enclosed in /* */.

A common stumbling block for beginners is writing so many comments that the code gets harder to read. Recording why a piece of logic is needed is valuable; restating what the code already says is not.

In real-world development, a special form called an XML documentation comment lets tools generate method documentation automatically.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run C# directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)