vb.net – 空检查VB
发布时间:2020-12-16 22:35:36 所属栏目:大数据 来源:网络整理
导读:所有我想做的是检查一个对象是否为null,但无论我做什么,如果它编译,它抛出一个NullReferenceException只是试图检查!这里是我做了: If ((Not (comp.Container Is Nothing)) And (Not (comp.Container.Components Is Nothing))) Then For i As Integer =
所有我想做的是检查一个对象是否为null,但无论我做什么,如果它编译,它抛出一个NullReferenceException只是试图检查!这里是我做了:
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书,搜索几个论坛,和一切应该工作不是!对不起,问这样的补救问题,但我只是需要知道。 只是这样你知道,调试器说,null对象是comp.Container
改变你的Ands到AndAlsos
A标准并将测试这两个表达式。如果comp.Container是Nothing,那么第二个表达式将引发一个NullReferenceException,因为你正在访问一个null对象的属性。
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |