c# – Adding comments to your code

It is always good practice to insert comments into your code so that you (as well as others) can understand what your code is doing.


I have released my new course on Udemy, Kubernetes By Example. Sign up now to get free lifetime access!

You can place a single line comment after a line of code, or on a line of it’s own using the “//” notation.

If you want to insert a multi-line comment, then you can begin it using /* and end the comment with */.

Here we the 2 comments types in actions

Program name: Hello World
Version: 1.0
Description: Opens up a terminal and displays "Hello World"

using System; // here we are importing the "System" namespace

// We are about to define the HelloWorld class.
class HelloWorld // This line is called the "class declaration" line
{ // curly brackets are used to structure the program, here we are indicating the start of the "HelloWorld" class.
static void Main() // This is the "method declaration" line

{ // Start of method’s code block
string message = "Hello World";
Console.WriteLine (message);
} // End of method
} // end of class