Vb.net 类型为'的值;一维数组';错误
我正在创建一个WCF服务,该服务中的一项是名为County的枚举类,其中包含此状态下的县列表。另一项是使用此枚举数组的名为Person的对象类(出于业务原因,需要一个数组,而不仅仅是一个县)。这不是我正在使用的此服务中的唯一数组,但其他数组涉及其他对象,而不是枚举,并且工作正常 我得到以下错误:Vb.net 类型为'的值;一维数组';错误,vb.net,visual-studio-2010,wcf,object,Vb.net,Visual Studio 2010,Wcf,Object,我正在创建一个WCF服务,该服务中的一项是名为County的枚举类,其中包含此状态下的县列表。另一项是使用此枚举数组的名为Person的对象类(出于业务原因,需要一个数组,而不仅仅是一个县)。这不是我正在使用的此服务中的唯一数组,但其他数组涉及其他对象,而不是枚举,并且工作正常 我得到以下错误: 无法将“LAService.County类型的一维数组”的值转换为“LAService.County类型的一维数组”,因为“LAService.County”不是从“County”派生的。 ”是什么意思
无法将“LAService.County类型的一维数组”的值转换为“LAService.County类型的一维数组”,因为“LAService.County”不是从“County”派生的。
”是什么意思?
?我曾经因为使用了错误的类型而出现过这个错误,但是问号是一个新事物。我如何克服这个错误
我的代码:
Public Enum County
Acadia
Allen
Ascension
...and on and on...
End Enum
<DataContract>
Public Class Person
<DataMember()>
Public ServiceCounty() As Nullable(Of County)
...and on and on...
End Class
Public Function FillPerson(ds as DataSet) As Person
Dim sPerson as Person
Dim iCounty as Integer = ds.Tables(0).Rows(0)("COUNTY")
Dim eCounty As String = eval.GetCounty(iCounty) 'This evaluates the county number to a county name string
Dim sCounty As String = DirectCast([Enum].Parse(GetType(County), eCounty), County)
Dim counties(0) As County
counties(0) = sCounty
sPerson = New Person With{.ServiceCounty = counties}
Return sPerson
End Function
公共枚举县
阿卡迪亚
艾伦
扬升
…而且不停地。。。
结束枚举
公共阶层人士
Public ServiceCounty()可为空(属于县)
…而且不停地。。。
末级
公共函数FillPerson(ds作为数据集)作为Person
暗语者
Dim iCounty作为整数=ds.表(0).行(0)(“县”)
Dim eCounty As String=eval.GetCounty(iCounty)'这将县编号计算为县名称字符串
Dim sCounty作为String=DirectCast([Enum].Parse(GetType(County),eCounty),County)
Dim县(0)作为县
县(0)=童子军
sPerson=具有{.ServiceCounty=县}的新人
回头客
端函数
在我构建代码之前,Visual Studio在单词“
countries
”处的“sPerson=newPerson With{.serviceCountry=countries}
”行显示上述错误。此外,我使用的所有其他数组都是以相同的方式创建的,只是使用对象而不是枚举。我已经尝试将我的Dim sCounty更改为String
,将Dim sCounty更改为country
,但是我得到了相同的错误。我也试着摆脱了DirectCast的行,只使用了Dim sCounty作为County=County.Acadia,但仍然得到了错误。?
是可空(T的)
的缩写。例如,Dim x As Nullable(对于整数)
的意思与Dim x As Integer?
的意思相同。因此,您可以通过更改此行来修复它:
Dim counties(0) As County
为此:
Dim counties(0) As Nullable(Of County)
或者,更简洁地说,这是:
Dim counties(0) As County?
?
是可为空(Of T)
的缩写。例如,Dim x As Nullable(对于整数)
的意思与Dim x As Integer?
的意思相同。因此,您可以通过更改此行来修复它:
Dim counties(0) As County
为此:
Dim counties(0) As Nullable(Of County)
或者,更简洁地说,这是:
Dim counties(0) As County?
啊,这是我第一次不得不使用Nullable。我只是想不需要县政府的财产。现在我知道了(知道是成功的一半)?在VB.netahh中也有同样的含义,这是我第一次使用Nullable。我只是想不需要县政府的财产。现在我知道了(知道是成功的一半)?在VB.Net中表示相同的内容