美文网首页
2020-05-12

2020-05-12

作者: 弱水河畔 | 来源:发表于2020-05-12 17:52 被阅读0次

    class Rectangle {

      num left, top, width, height;

      Rectangle(this.left, this.top, this.width, this.height);

      // 定义两个计算属性: right 和 bottom。

      num get right => left + width;

      set right(num value)=>left = value - width;


      num get bottom => top + height;

      set bottom(num value) => top = value - height;


    }

    void main() {

      var rect = Rectangle(3, 4, 20, 15);

      assert(rect.left == 3);


      rect.right = 12;

      assert(rect.left == -8);

    }

    相关文章

      网友评论

          本文标题:2020-05-12

          本文链接:https://www.haomeiwen.com/subject/qdkinhtx.html