是否可以在 VB.NET 中自动设置属性?

发布于 2024-11-01 21:12:01 字数 562 浏览 5 评论 0原文

事实上,我更喜欢使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぃ双果 2024-11-08 21:12:01

是的,您有两个不同的选项:

  1. 代码片段。这听起来与您在 Netbeans 中习惯的最相似。 IDE 将自动插入属性的“存根”,您所要做的就是填写详细信息。

    要实现这一点,您所要做的就是开始输入 property。 IntelliSense(自动完成)会建议您输入“Property”。当发生这种情况并且您看到“属性”一词突出显示时,请按 Tab两次。它将插入一个如下所示的片段:

    私有 newPropertyValue 作为字符串
    公共属性 NewProperty() 作为字符串
        得到
            返回新的属性值
        结束获取
        设置(ByVal 值作为字符串)
             新属性值 = 值
        结束组
    结束财产
    

    内置有很多这样的代码片段,所有这些代码片段的访问方式都与常见关键字相同。

  2. 自动属性。这是声明属性的简化语法,编译器将自动创建私有支持字段。您甚至可以使用此语法指定属性的默认值。它看起来像这样:

    公共属性 MyFavoriteColor As Color = Color.Green
    

    但请注意,这仅从 VB.NET 版本 10 开始可用。这意味着只要您使用 Visual Studio 2010 或更高版本,无论您使用的 .NET Framework 版本如何,它都可以工作定位。

Yes, you have two different options:

  1. 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:

    Private newPropertyValue As String
    Public Property NewProperty() As String
        Get
            Return newPropertyValue
        End Get
        Set(ByVal value As String)
             newPropertyValue = value
        End Set
    End Property
    

    There are lots of these snippets built-in, all accessed the same way for the common keywords.

  2. 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:

    Public Property MyFavoriteColor As Color = Color.Green
    

    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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文