Basic Comments

Line: Intro Line
Type: Walkthrough
You should have completed: Hello World This topic leads to: Counting Up

Summary

All programs can benefit from comments. Comments can be used to record any information you like. They are ignored by the compiler and do not affect the function of the program at all.

They are a vital tool in the programmer's arsenal, however, often used to:

Task

  1. Open the Hello World application you made earlier
  2. At the top of the Program.cs file insert the following code
    // Author: [Your Name Here]
    // SID: [Your SID]
    // Edited: [Today's Date]
  3. Replace the text in [] with your actual name, SID and the date

    The code is functionally unchanged, but important information has been added. Should another person have a problem or query about this code, they can now tell who wrote it and when, and therefore who to ask. By convention, comments usually appear before the line(s) of code that they refer to.
    You should include these comments in every code file you create.

  4. Compile and run the program

    There should be no change in what happens when you do so.

  5. Now add // to the beginning of the Console.WriteLine line in your code
  6. Compile and run the program

    The program behaviour has been altered as we have told the compiler that that line 'should be ignored'.

  7. 'Uncomment' that line by removing the // again, and check that the program runs correctly once more

Questions

  1. What else might you comment in Hello World? Hint: Is there a line of code whose purpose is unclear.