What is the difference in the two code blocks below? I expected them to return the same result, but they do not.
In the case where xml. @Type = "null", I want PatientMetricTypeID (zero integer) to be Nothing.
Block # 1: If ()
In this case, it ends as 0. It seems that Nothing is considered as a whole and is not converted to 0. I can understand why this can happen, but not completely ... I would like to understand exactly how this works, and if there is workaround.
Dim PatientMetricTypeID As Integer? = If(xml.@Type = "null",
Nothing,
CType([Enum].Parse(GetType(PatientMetricTypes), xml.@Type), Integer))
Block # 2: If
In this case, it ends as "No" - the expected behavior.
Dim PatientMetricTypeID As Integer?
If xml.@Type = "null" Then
PatientMetricTypeID = Nothing
Else
PatientMetricTypeID = CType([Enum].Parse(GetType(PatientMetricTypes), xml.@Type), Integer)
End If
source
share