在VB.Net中创建列表对象时出错

时间:2019-06-27 02:34:00

标签: vb.net collections

我是.Net框架的新手,但收到一条错误消息

  

类型'List(Of AdminSetEmployeeParams)'的值不能转换为   'AdminSetEmployeeParams'“

Dim SetNewEmployee As New List(Of AdminSetEmployeeParams)

  SetNewEmployee.Add(New AdminSetEmployeeParams With {
                    .departmentId = ddlDept.SelectedValue,
                    .familyName = txtLastOrSurname.Text,
                    .firstName = txtFirstOrGivenName.Text,
                    .secondName = txtSecondName.Text,
                    .contactPhone = txtPhone.Text,
                    .user = ""})

SetNewEmployee = EmployeeAPIService.AdminSetEmployee(SetNewEmployee).Result  

如何解决此错误?

更新:

System.Threading.Tasks
Public Class Task(Of TResult)


Public ReadOnly Property Result As TResult

1 个答案:

答案 0 :(得分:0)

可能是这样,但是很难确定:

Dim newEmployee As New AdminSetEmployeeParams

newEmployee = New AdminSetEmployeeParams With {
                .departmentId = ddlDept.SelectedValue,
                .familyName = txtLastOrSurname.Text,
                .firstName = txtFirstOrGivenName.Text,
                .secondName = txtSecondName.Text,
                .contactPhone = txtPhone.Text,
                .user = ""})

Dim newEmployeeResult As List(Of AdminSetEmployeeParams) = EmployeeAPIService.AdminSetEmployee(newEmployee).Result

我不确定您的API为什么在其结果中返回一个雇员列表(我假设是这样,因为您没有说您有一条错误消息,抱怨将结果分配给一个列表。 ..)),但给定的错误只会在API调用要求一位新员工并且您将新员工列表交给您的情况下才会发生

如果无法解决,请尝试最后一行

Dim newEmployeeResult As AdminSetEmployeeParams = EmployeeAPIService.AdminSetEmployee(newEmployee).Result

如果仍然无法解决,请编辑您的问题,以详细了解AdminSetEmployee接受哪种参数以及对象是什么类型。Result