【发布时间】:2010-12-22 17:02:36
【问题描述】:
下面两段代码有什么区别?我希望他们返回相同的结果,但他们没有。
在 xml.@Type = "null" 的情况下,我希望 PatientMetricTypeID(一个可为空的整数)最终成为 Nothing。
第 1 块:If()
在这种情况下,它最终为 0。看起来 Nothing 被视为整数并转换为 0。我可以理解为什么会发生这种情况但不完全......我想确切地了解如何这行得通,如果有解决方法。
Dim PatientMetricTypeID As Integer? = If(xml.@Type = "null",
Nothing,
CType([Enum].Parse(GetType(PatientMetricTypes), xml.@Type), Integer))
第 2 块:如果
在这种情况下,它以 Nothing 结束——预期的行为。
Dim PatientMetricTypeID As Integer?
If xml.@Type = "null" Then
PatientMetricTypeID = Nothing
Else
PatientMetricTypeID = CType([Enum].Parse(GetType(PatientMetricTypes), xml.@Type), Integer)
End If
【问题讨论】:
标签: .net vb.net if-statement