ARC
Well-known member
Alright so i've been trying to understand classes, and how to use them recently... and i still have some trouble with understanding the concept of using the objects that you add/create using the class.
My understanding as of now, is that you create a Class and create it's Properties -- each of which must have a Get/Set code in order for anything outside of the class file to access the values of said Properties. At this point, you dont have an object or instance yet. You just have the format in which future objects that are created using this class file must constrain to.
Then, you create an object/instance and set it's Properties... then you can use that object as a representation of the Class.
Am I to understand then, that this object, myWidget, is now an available object with the ID Property of 1, and I can do with it as I wish? Like for example, stick it in an array with other Widget Objects? Or maybe use the array to hold newly created Widgets at run time when a button OnClick is fired?
I'm not sure if that's even the correct usage of a class object, but that's why I'm asking Thanks in advance.
My understanding as of now, is that you create a Class and create it's Properties -- each of which must have a Get/Set code in order for anything outside of the class file to access the values of said Properties. At this point, you dont have an object or instance yet. You just have the format in which future objects that are created using this class file must constrain to.
Then, you create an object/instance and set it's Properties... then you can use that object as a representation of the Class.
VB.NET:
Public Class Widget
Private _ID As Integer
Public Property ID() As Integer
Get
Return Me._ID
End Get
Set(ByVal value As Integer)
Me._ID = value
End Set
End Property
End Class
VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As_
System.EventArgs) Handles Button1.Click
Dim myWidget As New Widget
myWidget.ID = 1
Me.Label1.Text = myWidget.ID
End Sub
Am I to understand then, that this object, myWidget, is now an available object with the ID Property of 1, and I can do with it as I wish? Like for example, stick it in an array with other Widget Objects? Or maybe use the array to hold newly created Widgets at run time when a button OnClick is fired?
I'm not sure if that's even the correct usage of a class object, but that's why I'm asking Thanks in advance.