Why should anonymous types cannot be passed around methods?

后端 未结 6 622
长情又很酷
长情又很酷 2021-01-22 04:27

What is the design decision to lean towards not returning an anonymous types from a method?

6条回答
  •  无人共我
    2021-01-22 05:18

    A lot of answers heere seem to indicatie that it is not possible because of the current syntax and rule. But the question is about changing them. I think it would be possible, but a little complicated and resulting in an awkward (error-prone) syntax. Like

    var f() { return new { A = "*", B = 1 }; }
    
    var x = f();
    

    The question is whether this adds sufficient value to the language to make it worth it.

提交回复
热议问题