2013-02-07 2 views
1

WCF 서비스를 만들고 서비스의 한 항목이이 상태의 카운티 목록이있는 카운티라는 이름의 열거 형 클래스입니다. 또 다른 항목은이 Enum의 배열을 사용하는 Person이라는 Object 클래스입니다 (사업상의 이유로 하나의 County뿐 아니라 배열이 필요합니다).이 서비스에서 내가 사용하고있는 다른 배열은 다른 배열과 관련이 있습니다 개체, 아니 열거 형, 그리고 잘 작동합니다.'1 차원 배열'유형의 값이 잘못되었습니다.

Value of type '1-dimensional array of type LAService.County' cannot be converted to '1-dimensional array of type LAService.County?' because 'LAService.County' is not derived from '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 

이, 비주얼 스튜디오 단어 'counties'에서 'sPerson = New Person With{.ServiceCounty = counties}'줄 위의 오류를 보여줍니다. Agains, 다른 모든 배열은 동일한 방법으로 생성되지만 Enums 대신 Objects를 사용합니다. 나는 이미 Dim sCounty as StringDim sCounty As County으로 변경하려고 시도했지만 동일한 오류가 발생합니다. 또한 DirectCast 행을 없애고 Dim sCounty As County = County.Acadia을 사용하려고 시도했지만 여전히 오류가 발생했습니다.

답변

1

?Nullable(Of T)의 줄임말입니다. 예를 들어 Dim x As Nullable(Of Integer)Dim x As Integer?과 동일한 의미입니다.

Dim counties(0) As County? 
+0

아, 그것이 내가 이번이 처음이다 :이,

Dim counties(0) As Nullable(Of County) 

또는 더 간결 : 여기에

Dim counties(0) As County 

: 그래서, 당신이 줄을 변경하여 문제를 해결할 수 있습니다 적으로 Nullable을 사용해야했습니다. 나는 단지 카운티 재산이 요구되지 않도록하고 싶었습니다. 지금 나는 알고있다. (그리고 아는 것은 전쟁의 반이다.) –

+0

? VB.Net에서 같은 것을 의미합니다. –

+0

@ChrisDunaway Thanks! –

관련 문제