我想要做的就是檢查一個對象是否爲空,但不管我做什麼,如果它編譯,它會拋出一個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