我有一类属性被用作 Web 服务的一部分。该类具有另一个类的列表作为其属性之一:
<Serializable()> _
Public Class LessonPlans
Public Property Teacher As String
Public Property RoomNumber As String
Public Property Subject As String
Public Property Students As List(Of Student)
End Class
<Serializable()> _
Public Class Student
Public Property FirstName As String
Public Property LastName As String
End Class
当我在本地应用程序上使用 LessonPlans 类时,执行以下操作没有问题:
Dim _NewLesson As New LessonPlans
_NewLesson.RoomNumber = "5"
_NewLesson.Subject = "English"
_NewLesson.Teacher = "Mr Smith"
Dim _Students As New List(Of Student)
Dim _NewStudent As New Student
_NewStudent.FirstName = "James"
_NewStudent.LastName = "Jones"
_Students.Add(_NewStudent)
_NewLesson.Students = _Students
但是,当我尝试在使用 Web 服务的应用程序上添加以下行时:
_NewLesson.Students = _Students
我收到一个错误:“System.Collections.Generic.List(Of WindowsApplication1.ws_lessons.Students)”类型的错误 6 值无法转换为“WindowsApplication1.ws_lessons.Students 的一维数组”。