Dart Tutorial

Dart Comments

The collection of statements known as comments are those that the Dart compiler ignores while the program is running. It is applied to improve the source code’s readable quality. Generally speaking, comments provide a concise overview of the code’s contents. Variables, functions, classes, and every statement that appears in the code can all be explained in detail. The comment should be used by programmers to improve their work. The Dart allows for three different kinds of comments.

Types of Comments

Dart offers three different types of remarks.

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

Single-line Comment

Applying comments to a single line is possible with the // (double-slash) character. Up to a line break, the single-line comments can be used.

Example

				
					void main(){  
    // This will print the given statement on screen  
    print("Welcome to JavaTpoint");  
}  
				
			

Output

				
					Welcome to JavaTpoint
				
			

The Dart compiler retunes the output and completely ignores the // (double-slash) statement.

Multi-line Comment

/*…..*/ can be used to apply comments across many lines when necessary. Anything typed inside the /*…*/ is ignored by the compiler, however multi-line comments cannot be nested inside of it. Now let’s look at an example.

Example

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

Output

				
					Welcome to JavaTpoint
				
			

Dart Documentation Comment

Document comments are used to create project/software package documentation or references. It can begin with /// or /* and be a single line or multi-line comment. The multiline comment can also be used with /// on successive lines. The Dart compiler ignores all of these lines save for the ones that are written inside curly brackets. Classes, functions, parameters, and variables can all be defined. Think about the example that follows.

Syntax

				
					///This  
///is   
///a example of  
/// multiline comment   
				
			

Example

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

Output

				
					Welcome to JavaTpoint
				
			
Share this Doc

Dart Comments

Or copy link

Explore Topic