1

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?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
gumuruh
  • 93
  • 4
  • 8

1 Answers1

7

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.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • 2
    +1 Yes, hehehe, the IDE is modern, huhuhu, it's all in the, waw, hehuhehu, [documentation](http://msdn.microsoft.com/en-us/library/z1x90c1b.aspx)! Hehuhawawgagagoogoogoo. – MarkJ Apr 15 '11 at 14:00
  • @MarkJ: Hmm, are you okay? You've obviously lost it. What, with thinking people read documentation? – Cody Gray - on strike Apr 15 '11 at 14:01
  • I guess they don't. Not if they're busy giggling about how they hate the language they're misusing. – MarkJ Apr 15 '11 at 14:04
  • huahaha... "if they're busying giggling" you just said? Hmmm... I think, "we're busy googling..." that's more appropriate. Heheheh... :D – gumuruh Jun 05 '11 at 10:40