是否可以在 VB.NET 中自动设置属性?
事实上,我更喜欢使用 Java 语言来开发应用程序。 但由于我现在的要求越来越严格,我需要跳到 VB.NET 嗯,是的...似乎需要适应一些。
不管怎样,为了在 Visual Studio 中创建这个 setter 和 getter 属性,我输入了很多内容;
Public Property supplierId() As Integer
Get
supplierId = iSupplierId
End Get
Set(ByVal value As Integer)
iSupplierId = value
End Set
End Property
我们是否有任何自动方法来设置和获取变量的这些属性? 因为我发现,当我使用 java 语言并使用 Netbeans 时,setter 和 getter 函数(或者有时我们称为方法)相当多的 CLICK 和 CLICK。一切都完成了!但是在这里...当我在 VB.Net 中尝试时,哇...键入,...呵呵。
我们是否有自动方法在 VB.NET 中插入变量的 setter 和 getter 属性?
I'm actually more comfortable in Java language for developing apps.
But since my requirement now is getting tighter, I need to jump forward into VB.NET
well yeah... seems need to adapt some a bit.
Anyway, I typed a lot for making this setter and getter properties inside visual studio;
Public Property supplierId() As Integer
Get
supplierId = iSupplierId
End Get
Set(ByVal value As Integer)
iSupplierId = value
End Set
End Property
Do we have any automatic way to do setting and getting those properties of a variable?
Because I found that while I'm in java language and using Netbeans, setter and getter function (or sometimes we called as method) is quite a bit CLICK and CLICK. Everything is done! But here... when I tried in VB.Net, waw... typed, ... hehehe.
Do we have automatically way to insert those setter and getter properties of a variable inside VB.NET?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您有两个不同的选项:
代码片段。这听起来与您在 Netbeans 中习惯的最相似。 IDE 将自动插入属性的“存根”,您所要做的就是填写详细信息。
要实现这一点,您所要做的就是开始输入
property
。 IntelliSense(自动完成)会建议您输入“Property”。当发生这种情况并且您看到“属性”一词突出显示时,请按 Tab 键两次。它将插入一个如下所示的片段:内置有很多这样的代码片段,所有这些代码片段的访问方式都与常见关键字相同。
自动属性。这是声明属性的简化语法,编译器将自动创建私有支持字段。您甚至可以使用此语法指定属性的默认值。它看起来像这样:
但请注意,这仅从 VB.NET 版本 10 开始可用。这意味着只要您使用 Visual Studio 2010 或更高版本,无论您使用的 .NET Framework 版本如何,它都可以工作定位。
Yes, you have two different options:
Code snippets. This sounds most similar to what you're used to in Netbeans. The IDE will automatically insert the "stub" for a property, and all you have to do is fill in the details.
To make this happen, all you have to do is start typing
property
. IntelliSense (auto-completion) will suggest that you're typing "Property". When that happens and you see the word "Property" highlighted, press the Tab key twice. It will insert a snippet that looks like this:There are lots of these snippets built-in, all accessed the same way for the common keywords.
Automatic properties. This is a simplified syntax for declaring properties, where the compiler will automatically create a private backing field. You can even specify a default value for the property using this syntax. It looks like this:
Note, however, that this is only available starting with VB.NET version 10. Meaning that it will work as long as you're using Visual Studio 2010 or a later version, regardless of the .NET Framework version that you are targeting.