0

这是我的课:

Public Class AddressForm

    Private Street As String

    Property Street_() As String
        Get
            Return Street
        End Get
        Set(ByVal value As String)
            If value IsNot Nothing Then
                Street = ""
            Else
                Street = value
            End If

        End Set
    End Property
End Class

这是我上面类 BusinessAddressDialog 的对象

如果 Not BussinessAddressDialog.Street_ = String.Empty(此处应用程序因空值而崩溃)在此行之后,我将在数据库中插入值

谢谢你的帮助

4

2 回答 2

1

尝试使用ShortCircuit技术:

If BussinessAddressDialog IsNot Nothing AndAlso _
   BussinessAddressDialog.Street_ = String.Empty Then
    ' Do you work here
End If

可能BussinessAddressDialog未初始化已设置为Nothing

于 2012-11-16T10:51:11.357 回答
0

如果该Street字段在您使用它之前不会被初始化,您可以在您Set的.valueNothing

Public Class AddressForm

    Private Street As String

    Property Street_() As String
        Get
            If Street Is Nothing then
                Return String.Empty
            Else
                Return Street
            End If
        End Get
        Set(ByVal value As String)
            If value Is Nothing Then
                Street = ""
            Else
                Street = value
            End If

        End Set
    End Property
End Class
于 2012-11-16T10:47:51.500 回答