【问题标题】:Expression-bodied members for VB.NET?VB.NET 的表达式体成员?
【发布时间】:2016-06-13 12:58:08
【问题描述】:

VB.NET 支持表达式体成员吗?到目前为止,它似乎在 c# 中拥有一切,如空条件、nameof、插值字符串、只能通过 ctor 访问的无实体自动属性等。

在c#中,语法是:

string FullName => FirstName + " " + LastName;

如何在 VB.NET 中实现这一点?

【问题讨论】:

    标签: vb.net properties


    【解决方案1】:

    不,VB 14 目前不支持它们,只有 C# 6。

    根据 roslyn Github Wiki Languages features in C# 6 and VB 14 上的表格:

    +---------------------------------------------------------------+--------+--------+
    |                            Feature                            |  C# 6  |  VB 14 |
    +---------------------------------------------------------------+--------+--------+
    | Auto-property initializers                                    | Added  | Exists |
    | Read-only auto-properties                                     | Added  | Added  |
    | Ctor assignment to getter-only autoprops                      | Added  | Added  |
    | Static imports                                                | Added  | Exists |
    | Index initializer                                             | Added  | No     |
    | Await in catch/finally                                        | Added  | No     |
    | Exception filters                                             | Added  | Exists |
    | Partial modules                                               | N/A    | Added  |
    | Partial interfaces                                            | Exists | Added  |
    | Multiline string literals                                     | Exists | Added  |
    | Year-first date literals                                      | N/A    | Added  |
    | Comments after implicit line continuation                     | N/A    | Added  |
    | TypeOf ... IsNot ...                                          | N/A    | Added  |
    | Expression-bodied members                                     | Added  | No     |
    | Null-conditional operators                                    | Added  | Added  |
    | String interpolation                                          | Added  | Added  |
    | nameof operator                                               | Added  | Added  |
    | #pragma                                                       | Added  | Added  |
    | Smart name resolution                                         | N/A    | Added  |
    | Read-write props can implement read-only interface properties | Exists | Added  |
    | #Region inside methods                                        | Exists | Added  |
    | Overloads inferred from Overrides                             | N/A    | Added  |
    | CObj in attributes                                            | Exists | Added  |
    | CRef and parameter name                                       | Exists | Added  |
    | Extension Add in collection initializers                      | Added  | Exists |
    | Improved overload resolution                                  | Added  | N/A    |
    +---------------------------------------------------------------+--------+--------+

    【讨论】:

    • 真可惜。似乎他们可以很容易地实现它。那好吧。什么是额外的 4 行代码
    • @oscilatingcretin 400% 在这种情况下 ;)
    • C#刚出来的时候我就试过了,但是太缺乏了我放弃了。在过去一年左右的时间里,我又回到了它,它终于足够强大,甚至比 VB 有足够的额外功能,当我不得不回去处理旧的 VB 项目时,我发现自己缺少 C#。 叹息
    猜你喜欢
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 2017-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-16
    相关资源
    最近更新 更多