VB.NET是否支持属性的自动获取器和设置器? [英] Does VB.NET support automatic getters and setters on properties?
本文介绍了VB.NET是否支持属性的自动获取器和设置器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在C#中,我可以这样做:
In C# I can do this:
public string myProperty { get; private set; }
这被称为自动获取/设置(据我所知) 。 VB.NET是否支持这些?到目前为止,使用我的属性,我所能做的就是:
This is referred to as an "automatic getter/setter" (from what I've heard). Does VB.NET support these? So far, with my properties, all I can do is this:
Public Property myProperty As String
Get
Return String.Empty
End Get
Private Set(ByVal value As String)
somethingElse = value
End Set
End Property
这非常笨拙。
所以...有更好的选择吗?
So... is there a better way?
推荐答案
是。
Public Property MyProperty As String
但是,您只能将其设为 VB 14(相对于2015年)或更高版本中的ReadOnly
。
However, you can only make it ReadOnly
in VB 14 (vs 2015) or later.
这篇关于VB.NET是否支持属性的自动获取器和设置器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文