VB 自动实现的属性未编译 [英] VB Auto Implemented Property not compiling

查看:34
本文介绍了VB 自动实现的属性未编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在对 VB 汽车属性进行了相当令人沮丧的研究之后.我决定不理他们.所以我有了这个代码.

After quite some frustrating research into VB auto properties. I decided to just ignore them. So I had this code.

Public Class Categoria
    Private _nome As String
    Public ReadOnly Property Nome As String
        Get
            Return _nome
        End Get
    End Property

    Public Sub New(nome As String)
        Me._nome = nome
    End Sub
End Class

但是 Visual Studio 有帮助,建议使用自动属性.我同意了,我之前什至尝试过,但他以点击这里的形式提供了帮助,我会去做.所以我做了.他做了完全相同的代码,我以前没有任何运气,一个字符一个字符.

But Visual Studio, being helpful, suggested to use auto-properties. I agreed, I even tried that before but he offered help in the form of a click here and I will do it. So I did. And he did exactly the same code I was not having any luck with before, char by char.

Public Class Categoria
    Public ReadOnly Property Nome As String

    Public Sub New(nome As String)
        Me.Nome = nome
    End Sub
End Class

有人可以解释为什么最后一段代码无法编译并显示 错误 BC30126:'ReadOnly' 属性必须提供一个 'Get'.?

Can someone shed some light as to why the last piece of code fails to compile with error BC30126: 'ReadOnly' property must provide a 'Get'.?

显然VS缺少和我一样的东西,所以我不再觉得自己那么愚蠢了.

Aparently VS is missing the same as I am, so I don't feel so stupid anymore.

推荐答案

正如@Heinzi 所指出的,并遵循他提供的上一篇文章.

As point out by @Heinzi and following a previous post he supplied.

如何在 ASP.NET 网站项目中使用最新的 VB.NET 语言级别?

更新 Microsoft.CodeDom.Providers.DotNetCompilerPlatform NuGet 包修复它,至少在我的开发机器上.

Updating the Microsoft.CodeDom.Providers.DotNetCompilerPlatform NuGet package fix it, in my dev machine at least.

这篇关于VB 自动实现的属性未编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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