suyuanhxx
V2EX  ›  问与答

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

  •  
  •   suyuanhxx · Apr 7, 2016 · 2050 views
    This topic created in 3695 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
        1
    suyuanhxx  
    OP
       Apr 7, 2016
    发现 v2 的 markdown 语法支持并不是很好
    LenaYan
        2
    LenaYan  
       Apr 7, 2016
    Builder 构建链式调用?
    Sin
        3
    Sin  
       Apr 7, 2016
    js 路过 ( ´◔‸◔`)
    Object.assign(this, {a, b})
    jsonline
        4
    jsonline  
       Apr 7, 2016
    _.pick
    suyuanhxx
        5
    suyuanhxx  
    OP
       Apr 7, 2016
    这个问题应该是只限于 Java 和 C#语法,不过其他语法可以参考下
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3066 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 88ms · UTC 13:28 · PVG 21:28 · LAX 06:28 · JFK 09:28
    ♥ Do have faith in what you're doing.