Dart注释

Dart汇总请点击这里

Dart 支持单行注释、多行注释和文档注释。

单行注释

单行注释以//开头。Dart 编译器会忽略// 和行末之间的所有内容。

void main() {
  // TODO: refactor into an AbstractLlamaGreetingFactory?
  print('Welcome to my Llama farm!');
}

多行注释

多行注释以/*开头并以*/结尾。 Dart 编译器会忽略/**/之间的所有内容(除非注释是文档注释;请参阅下一节)。多行注释可以嵌套。

void main() {
  /*
   * This is a lot of work. Consider raising chickens.

  Llama larry = Llama();
  larry.feed();
  larry.exercise();
  larry.clean();
   */
}

文档注释

文档注释是多行或单行注释,以///或开头/**。在连续的行上使用///具有与多行文档注释相同的效果。

在文档注释中,分析器会忽略所有文本,除非文本括在括号中。使用括号,您可以引用类、方法、字段、顶级变量、函数和参数。括号中的名称在记录的程序元素的词法范围内解析。

以下是引用其他类和参数的文档注释的示例:

/// A domesticated South American camelid (Lama glama).
///
/// Andean cultures have used llamas as meat and pack
/// animals since pre-Hispanic times.
///
/// Just like any other animal, llamas need to eat,
/// so don't forget to [feed] them some [Food].
class Llama {
  String? name;

  /// Feeds your llama [food].
  ///
  /// The typical llama eats one bale of hay per week.
  void feed(Food food) {
    // ...
  }

  /// Exercises your llama with an [activity] for
  /// [timeLimit] minutes.
  void exercise(Activity activity, int timeLimit) {
    // ...
  }
}

在类的生成文档中,[feed]成为方法文档的链接feed,并[Food]成为类文档的链接Food

解析 Dart 代码并生成 HTML 文档,您可以使用 Dart 的文档生成工具。dart doc

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值