在vb.net中,在类中定义字典类型

时间:2015-12-30 01:00:42

标签: vb.net dictionary

使用词典列表的新功能。

我有一个返回“任务对象”的api,定义为:

id As Integer

options As Dictionary(string,string)

所以我定义了一个名为Task的类来存储返回的“任务对象”。

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

我将从api返回的“任务对象”分配给此Task类。 我将选项定义为列表。这是对的吗?

我还必须阅读我班级中的选项,然后重新填充它以通过函数调用发送回api。

可以使用一些帮助......谢谢。

1 个答案:

答案 0 :(得分:0)

您可以直接将该属性添加到该类中:

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

您还可以为“options”参数创建Get和Set方法。