Results 1 to 4 of 4

Thread: [RESOLVED] Object properties in VS 2019

  1. #1

    Thread Starter
    Join Date
    Jan 2017

    Resolved [RESOLVED] Object properties in VS 2019

    Hi All

    I have just downloaded visual studio 2019 community edition having only ever
    used VS2008
    I have noted a lot of changes from VS2008 but one in particular is that when you create a public property
    on a form as you typed in 'Public Property XYZ as string'
    the IDE would automatically build the get and set parts of the property as well as end
    with End Property
    I see that VS2019 does not do this or am i missing something?

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002

    Re: Object properties in VS 2019

    Yeah, what you're missing is that the get and set parts often aren't needed. MS noted that the bulk of properties ended up being written like this:
    Private someVar As SomeType
    Public Property MyVar As SomeType
       Return someVar
     End Get
     Set (value as SomeType)
       someVar = value
     End Set
    End Property
    Back in 2008, they at least gave you the Get and Set. Starting with 2010, you didn't need to do anything more than the property itself:

    Public Property MyVar As SomeType

    You only had to write the Get/Set parts if you wanted to do more than the standard return a variable and set the variable. You still had to write out Read Only and Write Only properties, but for the rest, you didn't have to bother with writing stuff out.

    In one of the versions after 2010, even the Read Only and Write Only got the same treatment. Therefore, you only have the one line to write for most properties. You only need to explicitly write out the Get/Set if you need those blocks in order to put some custom code in there.

    Of course, you can still create them if you want to. All you have to do is type the Get, and you'll have what you used to have. MS just recognized that the vast majority of properties were all the same, and removed the need to type out all that stuff.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Join Date
    Jan 2017

    Re: Object properties in VS 2019

    Thanks Shaggy That makes sense, appreciate your reply

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Bristol, UK

    Re: [RESOLVED] Object properties in VS 2019

    You no longer have to specify the Get and Set, just the one line as you showed is enough.

    If you do want the full thing (because you want more code than just storing/retrieving a value), you can press a key (I think Tab) at the end of the line, and it will add the rest for you.

    edit: oops, I should have refreshed the page after being distracted for a couple of minutes!
    Last edited by si_the_geek; Apr 15th, 2019 at 09:58 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width