'1维数组''的值不能转换为''

时间:2014-06-27 19:55:31

标签: vb.net

以下错误发生在Building,Feature和ListingImage:

Error 17  Value of type '1-dimensional array of PropGenie_WebService.Building' cannot be converted to 'System.Collections.Generic.List(Of PropGenie_WebService.Building)'.

因此,我的网络服务使用列表,在列表中,您可以获得建筑物,功能,列表图像等。从代码中可以看到,建筑物可以具有区域单位大小。我试图使它成为数组但仍然得到这个错误。我整天都被困在这里,我真的被卡住了..

我在webservice中的代码:

  }, _
         .Features = {New Feature() With { _
             .Name = "Bedrooms", _
             .Count = "2" _
        }}, _
         .Images = {New ListingImage() With { _
             .Caption = "Awesomesauce", _
             .Url = "http://company.com/assets/index_background-84ec0c49973c354e38aea4b19d440e69.jpg" _
        }, New ListingImage() With { _
             .Caption = "Awesomesauce", _
             .Url = "http://company.com/assets/index_background-84ec0c49973c354e38aea4b19d440e69.jpg" _
        }}, _
         .Buildings = {New Building() With { _
             .AreaUnit = "sqm", _
             .AreaValue = 1000 _
        }} _
    }

建筑的一个例子:

Public Property AreaUnit() As String
        Get
            Return m_AreaUnit
        End Get
        Set(value As String)
            m_AreaUnit = value
        End Set
    End Property
    Private m_AreaUnit As String

来自Listings类的样本

 Buildings = New List(Of Building)()
        Features = New List(Of Feature)()
        Images = New List(Of ListingImage)()
...
Public Property Buildings() As List(Of Building)
        Get
            Return m_Buildings
        End Get
        Set(value As List(Of Building))
            m_Buildings = value
        End Set
    End Property

如果需要任何其他代码,请告诉我。

我尝试过但仍有错误

}, _
         .Features = New List(Of Feature) from { New Feature(){ With { _     'With Error: Expression Expected
             .Name = "Bedrooms", 
             .Count = "2" _     'Error: Not a member of listings
        }}, _
         .Images = New List(Of ListingImage) From { New ListingImage(){ With { _
             .Caption = "Awesomesauce", _
             .Url = "http://company.com/assets/index_background-84ec0c49973c354e38aea4b19d440e69.jpg" _      'Error: not a member of listings
        }, New ListingImage() With { _
             .Caption = "Awesomesauce", _
             .Url = "http://company.com/assets/index_background-84ec0c49973c354e38aea4b19d440e69.jpg" _
        }}, _
         .Buildings = New List(Of Building) From { New Building(){ With { _
             .AreaUnit = "sqm", _
             .AreaValue = 1000 _
        }} _
    }

1 个答案:

答案 0 :(得分:1)

.Buildings =  {New Building() With { _
         .AreaUnit = "sqm", _
         .AreaValue = 1000 _
    }}

创建一个Building数组,但是你需要一个列表:

.Buildings = New List(Of Building) From { New Building() With {...}}
相关问题