In c#, Comments are self-explanatory notes to provide detailed information about the code which we wrote in our applications.
It’s always a good practice to include comments in our c# code to provide detailed information about the functionality, like what a specific block or line of code can do. It will benefit anyone else who examines the code.
In c#, we can include the comments anywhere in the program without affecting our code. The comments in c# do not affect an application's performance because the comments won’t be compiled and executed by the compiler.
In c#, there are three types of comments available, those are
In c#, Single Line Comments are defined by using //
(double forward slash).
Following is the syntax of defining the single-line comments in the c# programming language.
Now we will see how to define a single-line comment in c# programs with examples.
Following is the example of defining the single-line comments in the c# programming language.
If you observe the above code, we defined a single-line comment to describe the specific block or line of code in our c# application.
When we execute the above c# program, we will get the result below.
This is how we can use single-line comments to provide detailed information about our c# application's functionality.
In c#, Multiline Comments are used to comment the multiple lines of code, and the multiple lines of comments are surrounded by slash and asterisk like /* …… */
.
Following is the syntax of defining the multiline comments in the c# programming language.
Now we will see how to define multiline comments in c# programs with examples.
Following is the example of defining the multiline comments in the c# programming language.
If you observe the above code, we defined multiline comments to describe the specific block or line of code in our c# application.
When we execute the above c# program, we will get the result below.
This is how we can use multiline comments to provide detailed information about our c# application's functionality.
In c#, XML Comments are a special type of comments, and these will be added above the definition of any user-defined type or member.
In c#, the XML Comments are defined by using ///
(triple forward slashes) and with XML formatted comment body.
Following is the syntax of defining the XML comments in the c# programming language.
Now, we will see how to define XML comments in c# programs with examples.
Following is the example of defining XML comments in the c# programming language.
If you observe the above code, we defined XML comments to describe the specific block or line of code in our c# application.
Here the <summary>
tag is used to add detailed information about a type or member and <param>
tag is used to describe the method parameters.
When we execute the above c# program, we will get the result below.
This is how we can use XML comments to provide detailed information about our c# application's functionality.