【发布时间】:2016-06-13 12:58:08
【问题描述】:
VB.NET 支持表达式体成员吗?到目前为止,它似乎在 c# 中拥有一切,如空条件、nameof、插值字符串、只能通过 ctor 访问的无实体自动属性等。
在c#中,语法是:
string FullName => FirstName + " " + LastName;
如何在 VB.NET 中实现这一点?
【问题讨论】:
标签: vb.net properties
VB.NET 支持表达式体成员吗?到目前为止,它似乎在 c# 中拥有一切,如空条件、nameof、插值字符串、只能通过 ctor 访问的无实体自动属性等。
在c#中,语法是:
string FullName => FirstName + " " + LastName;
如何在 VB.NET 中实现这一点?
【问题讨论】:
标签: vb.net properties
不,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 |
+---------------------------------------------------------------+--------+--------+
【讨论】: