2

What is the difference between these two implementation methods of a private variable? They seem functionally equivalent to me and the compiler doesn't seem to care.

Private myTempDir As String = TempAppDir & "\" & Name
Private Property MyTempDir As String = TempAppDir & "\" & Name
turbonate
  • 159
  • 2
  • 13

1 Answers1

1

The first line includes a Field/Variable and the second one an Auto-Implemented Property, which, as you can read in the MSDN documentation, is just a "quick version" of the conventional Property.

You can see advantages/disadvantages between Properties and Fields in the corresponding MSDN definition of Properties and in links like this one.

Also you have quite a few posts regarding advantages/disadvantages of Auto-Implemented Properties as compared to the traditional version:

These links are for C# but the ideas are easily transferable to VB.NET.

One of these last links refers to another pretty interesting one (also in C#): Properties vs. Public Variables.

Community
  • 1
  • 1
varocarbas
  • 12,354
  • 4
  • 26
  • 37