如飞镖文章所述:
".."语法调用方法(或setter或getter),但丢弃结果,然后返回原始接收器.
所以我认为这会起作用:
.addAll
这给了我,我不能叫错误null的..
因此很明显,..先.addAll使.clear()已被调用的结果的myList..clear()..addAll(otherList);.
我现在想,我有可能写这个:
(myList..clear()).addAll(otherList);.addAll()(如果我想得到结果..它是否正确?如果是,为什么决定给予myList(..clear().useResultOfClear()).addAll(otherList);优先权?这似乎非常违反直觉.这是为了避免这样的语法:.addAll?
Dart编程语言支持方法级联.方法级联将允许以下Silverlight/WPF C#代码:
var listBox = new ListBox();
listBox.Width = 200;
listBox.MouseEnter += (s, e) => Console.WriteLine("MouseEnter");
var button1 = new Button() { Content = "abc" };
button1.Click += (s, e) => Console.WriteLine("button1.Click");
listBox.Items.Add(button1);
var button2 = new Button() { Content = "def" };
button2.Click += (s, e) => Console.WriteLine("button2.Click");
listBox.Items.Add(button2);
ContentPanel.Children.Add(listBox);
Run Code Online (Sandbox Code Playgroud)
改为:
ContentPanel.Children.Add(
new ListBox()
..Width = 200
..MouseEnter += ((s, e) => Console.WriteLine("MouseEnter"))
..Items.Add(
new Button()
..Content = "abc";
..Click += ((s, e) => Console.WriteLine("button 1 Click"))) …Run Code Online (Sandbox Code Playgroud) 我正在做这样的事情:
new A()
..methodA()
..methodB()
.toString();
Run Code Online (Sandbox Code Playgroud)
这应该归还toString()吗?目前它正在返回新A对象.