我想在范围块中编写多条语句,如下所示:
long[] W = [0L];
long[] V = [0L];
array.each!(s => // "s" has following strings "3 4"
W ~= s.split(" ")[0].to!long;
V ~= s.split(" ")[1].to!long;
);
但是这会导致编译错误。有什么办法可以写出范围内的所有语句?
只需使用稍长的表单函数语法:
long[] W = [0L];
long[] V = [0L];
array.each!( (s) {
W ~= s.split(" ")[0].to!long;
V ~= s.split(" ")[1].to!long;
}
);
[(s) { x; y; z; }
适用于任何s => x
适用的地方,如果需要返回值,则使用s=>x
除外,长格式为(s) { return x; }
。