Vb.net get / set Properties without logic

Many of the articles I read on the Internet claim that when creating properties in vb.net they must use the get / set methods and a member variable of the private class.

Same:

Public Class Person
  Private _name as string
  public property Name  as string
    get
      return _name
    end get
    set(byval value as string)
      _name = value
    end set
  end property
end class

If there is no logic in the get / set property , why not write the same property:

Public class Person
  Public Property Name as string
end class

Is this because the properties were only intended to be accessed from outside the class, and you would save the variable in the class?

+5
source share
3 answers

The reason is that these guides and guides were published before VB.NET 4.0. There is no other reason not to use automatically implemented properties.

+6
source

, , , , , . , .

, , .

+1

Legacy Tutorials was a feature before. Auto-updated property notation gives you a short way to achieve consistent access to your class.

0
source

All Articles