C#.Net Comments

A comment is not a C# code and is ignored by the compiler. In C#, comment is necessary when we are dealing with lengthy sections of code, it can be useful to add reminders about exactly what we are doing. Comment indicates the purpose of the program so that others can also understand.

Types of comments:

  1. // - Single line comments are represented by double forward slashes.
  2. class Program
    {
        static void Main(string[] args)
        {
            //Console.WriteLine("I'm learning C Programming");
            //Console.WriteLine("I'm learning CPP Programming");
            //Console.WriteLine("I'm learning Java Programming");
            Console.WriteLine("I'm learning C#.Net Programming");
            Console.ReadLine();
        }
    }
    I'm learning C#.Net Programming
  3. /* ... */ - Multi-line comments are used to comment a block of code i.e. multiple statements.
  4. class Program
    {
        static void Main(string[] args)
        {
            /*Console.WriteLine("I'm learning C Programming");
            Console.WriteLine("I'm learning CPP Programming");
            Console.WriteLine("I'm learning Java Programming");*/
            Console.WriteLine("I'm learning C#.Net Programming");
            Console.ReadLine();
        }
    }
    I'm learning C#.Net Programming
Advertisement