← Back to C# Course | Chapter 1: Setup & Basics | Lesson 7 of 7

Comments

In this page:

  1. Comments

Comments

C# supports single-line comments with //, multi-line comments with /* */, and XML documentation comments with /// that tools can turn into documentation. Comments are ignored by the compiler and exist purely to explain code to humans. Good comments explain *why*, not what the code already makes obvious.

Note: IDEs like Visual Studio render /// summary comments as IntelliSense tooltips.

Example: Comments

markup
using System;

class Program
{
    /// <summary>
    /// Adds two integers together.
    /// </summary>
    static int Add(int a, int b)
    {
        // simple addition, no overflow checking
        return a + b;
    }

    static void Main(string[] args)
    {
        /* Call the helper and print the result */
        Console.WriteLine(Add(2, 3));
    }
}
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.