Comments in C#

Notes:

Comments in C# Programming Language:
- Comments are something like notes in the code.

Comments are used to explain the code logic,
so that we can be able to understand the code later
as well as
other developers can also be able to read and understand the code easily.
Comments are used to increase the readability and understandability of the source code.

Comments are used to document the source code. (Documentation)

Note:
Comments are ignored by the C# compiler.

Types of comments in C#:
There are 3 types of comments in C#

Single line comment: (// comment goes here)
- Anything is written after // symbols in the line is treated as a comment
- // are used to write single line comments

Multiline comment: (/* comment goes here */)
- Anything is written in between /* and */ is treated as a comment
- /* and */ are used to write multiple lines of comments

Documentation comment: ( /// uses XML syntax )
- Anything is written after /// symbols using XML syntax is treated as a comment
- /// are used to document a structure, class, interface etc. i.e. any used defined data type; which gives extra information to the user

Note: If we don’t want to execute some part(s) of the code, we can comment them so that they can be ignored by the compiler.

Example Code:

using System;
namespace CommentsDemo
{
/// <summary>
/// Program is a main class for CommentsDemo project
/// </summary>
class Program
{
static void Main(string[] args)
{
// Console is a class, it is available inside System namespace
// WriteLine is a method, it is available inside Console class

/*
* Console is a class
* WriteLine is a method
* ReadKey is a method
*/

Console.WriteLine("Hello world");
Add(2, 3);
Console.ReadKey();
}

/// <summary>
/// Add method displays sum of 2 integer numbers
/// </summary>
/// <param name="num1">Enter num1</param>
/// <param name="num2">Enter num2</param>
static void Add(int num1, int num2)
{
Console.WriteLine(num1 + num2);
}
}
}

Example Code:

/*
Author : Manjunath Chidre
Program: for displaying Hello world! 3 times
*/
#include <iostream>
using namespace std;
int main()
{
// cout is a built in object, cout stands for console output
// cout is declared inside iostream header file

// cout << "Hello world!" << endl;

/*
cout << "Hello world!" << endl;
cout << "Hello world!" << endl;
*/
cout << "Hello world!" << endl;
cout << "Hello world!" << endl;
cout << "Hello world!" << endl;

return 0;
}