我想要做的就是检查一个对象是否为空,但不管我做什么,如果它编译,它会抛出一个NullReferenceException
只是试图检查!下面是我做了什么:空值检查在VB
If ((Not (comp.Container Is Nothing)) And (Not (comp.Container.Components Is Nothing))) Then
For i As Integer = 0 To comp.Container.Components.Count() - 1 Step 1
fixUIIn(comp.Container.Components.Item(i), style)
Next
End If
If ((Not IsDBNull(comp.Container)) And (Not IsDBNull(comp.Container.Components))) Then
For i As Integer = 0 To comp.Container.Components.Count() - 1 Step 1
fixUIIn(comp.Container.Components.Item(i), style)
Next
End If
If ((Not IsNothing(comp.Container)) And (Not IsNothing(comp.Container.Components))) Then
For i As Integer = 0 To comp.Container.Components.Count() - 1 Step 1
fixUIIn(comp.Container.Components.Item(i), style)
Next
End If
If ((Not (comp.Container Is DBNull.Value)) And (Not (comp.Container.Components Is DBNull.Value))) Then
For i As Integer = 0 To comp.Container.Components.Count() Step 1
fixUIIn(comp.Container.Components.Item(i), style)
Next
End If
我已经通过VB的书看了,搜查几个论坛,并应工作都没有!对不起,问这样一个补救问题,但我只需要知道。
只要你知道,调试器说,空对象是comp.Container
得到的东西的工作,你需要等待一个答案,有时事情可重构的工作..喜欢在这种情况下,使用一对嵌套的IFS。 – 2011-04-08 00:25:30