列出 dart 中双点 (.) 的使用? [英] List use of double dot (.) in dart?

查看:27
本文介绍了列出 dart 中双点 (.) 的使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时我看到这个List list = [];

然后list..add(color)

使用 1 dot(.) 和 2 dot(..) 有什么区别?

What's the difference between using 1 dot(.) and 2 dot(..)?

推荐答案

.. 被称为 级联符号.如果你想在同一个对象上调用多个方法,它允许你不重复同一个目标.

.. is known as cascade notation. It allows you to not repeat the same target if you want to call several methods on the same object.

List list = [];
list.add(color1);
list.add(color2);
list.add(color3);
list.add(color4);

// with cascade

List list = [];
list
  ..add(color1)
  ..add(color2)
  ..add(color3)
  ..add(color4);

这篇关于列出 dart 中双点 (.) 的使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆