Comment in C# is basically used for explaining programs and lines of code do. Comments are ignored by the compiler. There are three types of comments.
1- Single line comment - It is used for commenting the single line of code.
// Single line Comment
2- Multi-line comment - It is used for commenting the multiple lines of code.
/* Multiple
line of code comment */
C# Program to explain the single line and multiline comments -
class Hello {
// Single Line Comment -- Function to print Message
public static void PrintMessage(string message)
{
Console.WriteLine (message);
}
// Main function
static void Main(string[] args)
{
/* Multiline Comment --
Define a variable of
string type and assign
value to it*/
string msg = "Study Cube Learning";
PrintMessage (msg); // Calling function
}
}
3- XML Comment - It is used for commenting the multiple lines of code for better understanding the program does.
class Hello {
/// <summary>
/// Method to show string message
///</summary>
///<pram name =“message”></param>
public static void PrintMessage (string message)
{
Console.WriteLine (message);
}
static void Main(string[] args)
{
string msg = "Study Cube Learning";
PrintMessage (msg);
}
}
No comments:
Post a Comment