Dart Comments

 

Dart Comments

Comments are the set of statements that are ignored by the Dart compiler during the program execution. It is used to enhance the readability of the source code. Generally, comments give a brief idea of code that what is happening in the code. We can describe the working of variables, functions, classes, or any statement that exists in the code. Programmers should use the comment for better practice. There are three types of comments in the Dart.

Types of Comments

Dart provides three kinds of comments

  • Single-line Comments
  • Multi-line Comments
  • Documentation Comments

Single-line Comment

We can apply comments on a single line by using the // (double-slash). The single-line comments can be applied until a line break.

void main(){  

  1.     // This will print the given statement on screen  
  2.     print("Welcome to JavaTpoint");  
  3. }  

Output:

Welcome to JavaTpoint

The // (double-slash) statement is completely ignored by the Dart compiler and retuned the output.

Multi-line Comment

Sometimes we need to apply comments on multiple lines; then, it can be done by using /*…..*/. The compiler ignores anything that written inside the /*…*/, but it cannot be nested with the multi-line comments. Let's see the following example.

Example -

  1. void main(){  
  2.     /* This is the example of multi-line comment 
  3.     This will print the given statement on screen */  
  4.       
  5.     print("Welcome to JavaTpoint");  
  6. }  

Output:

Welcome to JavaTpoint

Dart Documentation Comment

The document comments are used to generate documentation or reference for a project/software package. It can be a single-line or multi-line comment that starts with /// or /*. We can use /// on consecutive lines, which is the same as the multiline comment. These lines ignore by the Dart compiler expect those which are written inside the curly brackets. We can define classes, functions, parameters, and variables. Consider the following example.

Syntax

  1. ///This  
  2. ///is   
  3. ///a example of  
  4. /// multiline comment   

Example -

  1. void main(){  
  2.     ///This is   
  3.     ///the example of   
  4.     ///multi-line comment  
  5.     ///This will print the given statement on screen.  
  6.     print("Welcome to JavaTpoint");  
  7. }  

Output:

Welcome to JavaTpoint


Comments