0

我正在使用集合和结构将一些解析的数据存储在一个类中,但是当我尝试检索数据时它为空。在 form1 上,我可以获得所有原始数据的响应字符串。我是否正确地将解析的数据添加到集合中?我在form1上正确调用了吗?

Private Sub btnStart_Click(sender As System.Object, e As System.EventArgs) Handles btnStart.Click
    Dim dloader as new Downloader(blah)
 'this does not work
    Dim test as new _ListInfo
      msgbox(test.Name) ' produces an empty message box
'this works
     msgbox(dloader.Download)
End Sub

这是我的课程代码:

Public Structure _Info
  Dim Name As String
End Structure

Public Class Downloader
  Dim _ListCollection As New Collection(Of _ListInfo)

Public ReadOnly Property ListCollection() As Collection(Of _ListInfo)
    Get
        ListCollection = _ListCollection
    End Get
End Property

Public Function Download() As String
  'doing the download
  ParseList()
  Return _ResponseString
End Function    

Private Sub ParseList()
    _ListCollection.Clear()
 Dim Name As String
 Dim MyInfo As _ListInfo
   MyInfo.Name = Name
    _ListCollection.Add(MyInfo)
End Sub
4

1 回答 1

1

你为什么期望它起作用?您只是在更新结构并访问属性。你不想做类似的事情:

Dim dloader as new Downloader(blah)
dloader.Download()
' Show first name.
MsgBox(dloader.ListCollection(0).Name)
于 2013-10-04T14:01:42.890 回答