Dart Comments

In this tutorial you will learn about the Dart Comments and its application with practical example.

Dart Comments

Comments are a set of statements that are not executed by the compiler. The use of comments makes it easy for humans to understand the source code. Usually comments gives you inside or explanation about the variable, method, class or any statement that exists in source code. The comment statements are ignored during the execution of the program.

Types of Dart Comments

In Dart, there are 3 types of comments.

  • Dart Single Line Comment
  • Dart Multi Line Comment
  • Dart Documentation Comment

Dart Single line Comments

A ‘//’ (double forward slash) is used to specify a single line comment, which extends up to the newline character. This can be used to comments-out everything until a line break

Syntax:-

Example:-

Output:-

Dart Multi line Comments

If you want to comment multiple lines then you can do it using /* and */, everything in between from /* to */ is ignored by the compiler-

Uses:-

  • Useful for commenting out a section of code
  • Cannot be nested within other multi-line comments

Syntax:-

Example:-

Output:-

Dart Documentation Comment

This is a special type of comment mainly used to generate documentation or reference for a project/software package. Documentation comments are multi-line or single-line comments that begin with /// or /**. Using /// on consecutive lines has the same effect as a multi-line doc comment. The Dart compiler ignores all text inside a documentation comment except it is enclosed in brackets. The brackets are used to refer classes, methods, fields, top-level variables, functions, and parameters. The names in brackets are resolved in the lexical scope of the documented program element.

Recommended:-  Dart Metadata

Uses:-

  • Similar to multi-line comments but used to document dart code (classes, methods, expressions)

Syntax:-

In this tutorial we have learn about the Dart Comments and its application with practical example. I hope you will like this tutorial.