I'm creating a class called Job with a property called Tasks. Tasks is an array of the type Task (another class). I can return the Tasks collection using a public readonly property that returns the array, but how do I implement an add method to add a task to Tasks?
I started with a simple class and researched Write Own "Add" Method For An Array and Add new item to Object Array and many others. I have an inherent mistake in my thinking and I do not know the right terms to find the correct solution.
Public Class Job
Private _taskcount As Integer
Private _tasks() As Task
Public ReadOnly Property TaskCount
Get
Return _taskcount
End Get
End Property
Public ReadOnly Property Tasks As Task()
Get
Return tasks
End Get
End Property
End Class
I would love to be able to dim myjob as new job
and then do myjob.tasks.add
, but I do not have an idea where in the class definition the Add method goes. Help with adding the Add method would be greatly appreciated.
Edit: I also understand that the property TaskCount should be implemented as Tasks.Count
. So my underlying problem is the implementation of properties and methods of a property.