如何将值添加到列表中的项目。列表类型是这个类: -
<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服务结果并将其作为不同的类输出。
任何帮助都将不胜感激。
答案 0 :(得分:2)
您尚未在列表中插入任何内容,因此列表为空。
Dim newWeeksOnHold As New List(Of TOBWeeksHeld)
newWeeksOnHold.Add(New TOBWeeksHeld) ' <-- insert a new item
With newWeeksOnHold(0)
'...
End With
答案 1 :(得分:0)
在设置元素之前,您需要在列表中添加一个条目。 newWeeksOnHold仍然是空的