0

我对在 5 个服务器上运行的相同服务进行相同的 SOAP 调用。返回的所有TWeeksHeld集合都需要连接在一起成为同一对象的输出TDAEHeldList版本 ( )。这是我的课程:

Partial Public Class TDAEHeldList      
    Private siteIdField As String        
    Private countField As Integer        
    Private returnCodeField As String        
    Private errorMessageField As String        
    Private daeWeeksHeldField() As TWeeksHeld
End Class

Partial Public Class TWeeksHeld        
    Private checkInField As String        
    Private resortNameField As String        
    Private countryField As String        
    Private regionField As String        
    Private localityField As String        
    Private weekIdField As String        
    Private bedroomsField As String        
    Private sleepsField As String        
    Private bookingTypeField As String        
    Private resortIdField As String        
    Private timeToExpiryField As String        
    Private specialFlagField As String        
    Private extMemberNoField As String        
    Private stockDisplayField As String        
    Private ownerBusCatCodeField As String
End Class

每次调用都需要将集合的内容添加daeWeeksHeldField()到输出类的daeWeeksHeldField()集合中。

我有以下工作:

Dim returnData As New TDAEHeldList
Dim weeksOnHold As New TDAEHeldList
Dim weeksOnHoldArray As TWeeksHeld
weeksOnHold = WSCaller.GetForeignWeeksOnHold(siteID,affiliateMemberID)

然后尝试添加

weeksOnHoldArray += String.Concat(weeksOnHoldArray, weeksOnHold.daeWeeksHeldField)

其次是:

returnData.daeWeeksHeldField = weeksOnHoldArray.ToArray(GetType(TWeeksHeld))

我也试过:

for Each x As Object In weeksOnHold.daeWeeksHeld
  weeksOnHoldArray.Add(x)
Next

加上其他一些谷歌搜索的技术。我想做的事情是否可能,如果是,它是如何完成的?

4

1 回答 1

0

您将daeWeeksHeldField属性称为集合,但它不是集合。它是一个数组。数组当然有它们的用途,但在这种情况下,你真正想要的是一个集合。集合允许您轻松添加新项目。另一方面,数组不能自动动态增长,因此如果列表的大小不固定,使用起来会很麻烦。

最常用的集合,也是我推荐的集合,是List(Of T). 以下是您将如何使用它:

Dim combinedWeeksOnHold As New List(Of TWeeksHeld)
Dim weeksOnHold1 = WSCaller1.GetForeignWeeksOnHold(siteID1, affiliateMemberID1)
If weeksOnHold1.daeWeeksHeldField IsNot Nothing Then
    combinedWeeksOnHold.AddRange(weeksOnHold1.daeWeeksHeldField)
End If
Dim weeksOnHold2 = WSCaller2.GetForeignWeeksOnHold(siteID2, affiliateMemberID2)
If weeksOnHold2.daeWeeksHeldField IsNot Nothing Then
    combinedWeeksOnHold.AddRange(weeksOnHold2.daeWeeksHeldField)
End If

如果您真的需要它们的数组,您可以随时调用List(Of T).ToArray,如下所示:

Dim array() As TWeeksHeld = combinedWeeksOnHold.ToArray()
于 2013-02-14T18:43:13.067 回答