VB.NET 的表达式主体成员? [英] Expression-bodied members for VB.NET?

查看:47
本文介绍了VB.NET 的表达式主体成员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VB.NET 是否支持表达式主体成员?到目前为止,它似乎拥有 C# 中的所有内容,例如空条件、nameof、内插字符串、只能通过 ctor 访问的无实体自动属性等.

Does VB.NET support expression-bodied members? So far, it seems to have everything in c# like null conditionals, nameof, interpolated strings, bodiless auto properties accessible only via ctor, etc.

在c#中,语法是:

string FullName => FirstName + " " + LastName;

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

How can I achieve this in VB.NET?

推荐答案

不,它们目前在 VB 14 中不受支持,仅在 C# 6 中受支持.

No, they are not currently supported in VB 14, only C# 6.

根据 roslyn Github Wiki 上的表格 C# 6 和 VB 14 中的语言特性:

According to the table on the 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    |
+---------------------------------------------------------------+--------+--------+

这篇关于VB.NET 的表达式主体成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆