Previous Lecture Complete and continue  

  Comments

In C# (similarly to JavaScript), you can use comments to explain your code and to make it more readable by others. This becomes important as the size of your code increases; and it is also important if you work in a team, so that other team members can understand your code and make amendments in the right places, if and when it is needed.

Code that is commented is usually not executed. There are two ways to comment your code in C# using either single- or multi-line comments.

In single-line comments, a double forward slash is added at the start of a line or after a statement, so that this line (or part thereof) is commented, as illustrated in the next code snippet.

//the next line prints Hello in the console window

print (“Hello”);

//the next line declares the variable name

string name;

name = “Hello”;//sets the value of the variable name

In multi-line comments, any code between the characters forward slash and star “ /*” and the characters star and forward slash “*/” will be commented, and this code will not be executed. This is also referred as comment blocks.

/* the next lines after the comments will print the message “hello” in the console window

we then declare the variable name and assign a value

*/

print(“Hello”);

string name;

name = “Hello”;//sets the value of the variable name

//print (“Hello World”)

/*

string name;

name = “My Name”;

*/

You can drag and drop this file to an empty object, play the scene and see the result in the Console window. You can also, if you wish, modify the file using Mono develop or any script editor of your choice.

Download