1

Both methods below give the same result, what is the reason you would use one of the other.
I'm struggling to figure out what the subtle differences are between using a String Function over using a Read Only Property.

Method 1

Public Function GetUserName() as String 
   Return "foobar"
End Function

Method 2

Public ReadOnly Property UserName() as String 
   Get
      Return "foobar"
   End Get
End Property
Jordan Coulam
  • 359
  • 1
  • 13
  • 1
    It's about encapsulation: properties expose data while methods expose logic. It all boils down to the expectations of the caller. A property should return the data and hence run quickly and without side-effects. A method involves computation and may have side-effects inside the object and/or a longer running time. – WeSt Mar 17 '15 at 11:58
  • WeSt: Thank you I did search the site before however I did not see that question in my results. Could you make your second comment a Answer please so I can mark it. You explained it well. – Jordan Coulam Mar 17 '15 at 12:12
  • Please upvote the original question and/or answer rather than rewarding me the answer :) – WeSt Mar 17 '15 at 12:17
  • I will do once I can,I did read the other post just didn't quite understand it still until I read your comment. I preferred your wording on the matter made allot more sense to me. Thank you for the help. – Jordan Coulam Mar 17 '15 at 12:19

0 Answers0