0

I've created a Class called Enemy. I wanted to create automatic Getters and Setters like you do on Dev-C++, but it seems like you can't, instead Visual can create Properties.

I defined this variable

Private name as String

The automatic generated Property is:

Public Property nameProp() As String
    Get
        Return name
    End Get
    Set(ByVal value As String)
        name = value
    End Set
End Property

When I create an Enemy object, how do I access name getter and setter individualy?

Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
RicRev
  • 29
  • 1
  • 1
  • 8
  • 1
    If you want to declare a simple property for a class in one line of code, you can use `Public Property Name As String`. It will function like the `nameProp` property in your code and does not require you to declare the private field `name` to store the data. – Blackwood Aug 02 '17 at 00:24
  • Okay, that shortens the code, but how do I get or set anything using this? – RicRev Aug 02 '17 at 00:35
  • I'm not sure what you mean. You can use this to get and set the Name property. If you want to be able to get and set some other property, you need to add another property. – Blackwood Aug 02 '17 at 00:38
  • `myEnemy.Name = "Chris"`. Also take a cue from the legion of classes you interact with in the NET framework...none of the properties include meta data like `...prop`. – Ňɏssa Pøngjǣrdenlarp Aug 02 '17 at 00:48
  • https://stackoverflow.com/q/460027/1070452 – Ňɏssa Pøngjǣrdenlarp Aug 02 '17 at 00:56

0 Answers0