suyuanhxx
V2EX  ›  问与答

当赋值语句很多时如何优雅的编写赋值语句

  •  
  •   suyuanhxx · Apr 7, 2016 · 2388 views
    This topic created in 3862 days ago, the information mentioned may be changed or developed.

    赋值语句都是一些很简单的搬运工作,和构造实例。
    this.a = a;
    this.b = b;
    ......
    就像这种简单的搬运,如何优雅的编写代码?
    class a{ public string str; }
    class b{ public a{get;set;}; }
    当 a 中变量很多时,如何优雅的给 b 的实例中 a 赋值?

    5 replies  •  2016-04-07 15:03:54 +08:00
    suyuanhxx
    suyuanhxx
    OP
    Apr 7, 2016
    1
    发现 v2 的 markdown 语法支持并不是很好
    LenaYan
    LenaYan
    Apr 7, 2016
    2
    Builder 构建链式调用?
    Sin
    Sin
    Apr 7, 2016
    3
    js 路过 ( ´◔‸◔`)
    Object.assign(this, {a, b})
    jsonline
    jsonline
    Apr 7, 2016
    4
    _.pick
    suyuanhxx
    suyuanhxx
    OP
    Apr 7, 2016
    5
    这个问题应该是只限于 Java 和 C#语法,不过其他语法可以参考下
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3015 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 12:07 · PVG 20:07 · LAX 04:07 · JFK 07:07
    ♥ Do have faith in what you're doing.