0

如何将值添加到列表中的项目。列表类型是此类:-

<SoapType("TOBWeeksHeld", "urn:daeoverbrandIntf")> _
Public Class TOBWeeksHeld
    Public siteID As String
    Public checkIn As String
    Public resortName As String
    Public country As String
    Public region As String
    Public locality As String
    Public weekId As String
    Public bedrooms As String
    Public sleeps As String
    Public bookingType As String
    Public resortId As String
    Public timeToExpiry As String
    Public specialFlag As String
    Public extMemberNo As String
End Class

我尝试的一切,例如:-

Dim newWeeksOnHold As New List(Of TOBWeeksHeld)
With newWeeksOnHold(0)
.siteID = siteID
.checkIn = weeksOnHold.daeWeeksHeld(i).checkIn()
.resortName = weeksOnHold.daeWeeksHeld(i).resortName()
.country = weeksOnHold.daeWeeksHeld(i).country()
.region = weeksOnHold.daeWeeksHeld(i).region()
.locality = weeksOnHold.daeWeeksHeld(i).locality()
.weekId = weeksOnHold.daeWeeksHeld(i).weekId()
.bedrooms = weeksOnHold.daeWeeksHeld(i).bedrooms()
.sleeps = weeksOnHold.daeWeeksHeld(i).sleeps()
.bookingType = weeksOnHold.daeWeeksHeld(i).bookingType()
.resortId = weeksOnHold.daeWeeksHeld(i).resortId()
.timeToExpiry = weeksOnHold.daeWeeksHeld(i).timeToExpiry()
.specialFlag = weeksOnHold.daeWeeksHeld(i).specialFlag()
.extMemberNo = weeksOnHold.daeWeeksHeld(i).extMemberNo()
End With

在调试器中给我同样的错误,即索引超出“With newWeeksOnHold(0)”行的范围。我猜这是因为列表是空的,我告诉它去一个特定的索引。但是,我尝试过添加、插入和其他一些操作,但均无济于事。

这样做的目的是读入 Web 服务结果并将其作为不同的类输出。

任何帮助,将不胜感激。

4

2 回答 2

2

您没有在列表中插入任何内容,因此列表为空。

Dim newWeeksOnHold As New List(Of TOBWeeksHeld)
newWeeksOnHold.Add(New TOBWeeksHeld) ' <-- insert a new item
With newWeeksOnHold(0)
'...
End With
于 2013-02-16T14:12:24.263 回答
0

在设置元素之前,您需要在列表中添加一个条目。newWeeksOnHold 仍为空

于 2013-02-19T17:36:13.547 回答