user3020047 user3020047 - 4 years ago 142
Vb.net Question

In vb.net, defining a dictionary type in a class

New to using a Dictionary list.

I have an api that is returning a "task object" defined as:

id As Integer

options As Dictionary(string, string)

So I am defining a class called Task to store the returned "task object".

Public Class Task
Private _id As Integer

Public Property Id() As Integer
Get
Return _id
End Get

Set(value As Integer
_id = value
End Set
End Property

Private _optionlist As New List(Of Option)

Public Property OptionList() As List(Of Option)
Get
Return _optionlist
End Get

Set(ByVal value As List(Of Option))
_optionlist = value
End Set
End Property
End Class

Public Class Option
Private _key As String

Public Property Key() As String
Get
Return _key
End Get

Set(value As String)
_key = value
End Set
End Property

Private _value As String

Public Property Value() As String
Get
Return _value
End Get

Set(value As String)
_value = value
End Set
End Property
End Class


I will assign the "task object" returned from the api to this Task class.
I defined options as a list. Is that correct?

I will also have to read the option in my class and later repopulate it to send back to the api via function call.

Could use some help...thanks.

Answer Source

You can add the property to the class directly:

Public Class Task
  Private _id As Integer
  Private options As Dictionary(of string, string)

You can also create Get and Set methods for the "options" parameter.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download