三、Dart计算属性

1,787 阅读1分钟
void main() {
var rect = Rectangle();
rect.width = 20;
rect.height = 30;

print(rect.area());

}

class Rectangle {
num width, height;

num area() {
return width * height;
}
}

比较

void main() {
var rect = Rectangle();
rect.width = 20;
rect.height = 30;

print(rect.area);
}

class Rectangle {
num width, height;

num get area {
return width * height;
}
}