我有一个枚举,它是数组列表(可选,你可以添加最多5次的项目)
Public DiseaseTreatment() As TreatmentsetDiseaseTreatment
Public Enum TreatmentsetDiseaseTreatment
'''<remarks/>
<System.Xml.Serialization.XmlEnumAttribute("01")> _
Item01
''<remarks/>
Antibiotics
''<remarks/>
<System.Xml.Serialization.XmlEnumAttribute("02")> _
Item02
'''<remarks/>
<System.Xml.Serialization.XmlEnumAttribute("Pain Killers)")> _
PainKillers
破
Dim temptreatment As List(Of TreatmentsetDiseaseTreatment)= New List(Of TreatmentsetDiseaseTreatment)()
temptreatment.Add("Painkiller")
For i As Integer = 0 To temptreatment(i) - 1
test.TreatmentTypes(i) = temptreatment(i)
Next
当我将鼠标悬停在tempTreatment(i)
上时,它有正确的字符串"painkiller"
,所以我不明白它是如何投掷NullReferenceException
的?
答案 0 :(得分:4)
您希望在数组末尾停止,而不是在数组中x项的末尾停止。
For i As Integer = 0 To temptreatment.Count - 1
不
For i As Integer = 0 To temptreatment(i) - 1