我刚刚启用了“Option Strict”,并根据弹出消息的建议,它建议我更改我的声明。以前,该语句如下面的代码所示。它建议我将 = "" 更改为 Is Nothing。但是,这不会显示消息“没有电子邮件记录”声明。我编码是否正确。
作为 vb.net 的新手,我需要一些专家建议。谢谢
原始代码
If Email = "" Then
txtEmail.Text = "No email on record" ' blank if dbnull values
txtEmail.ForeColor = Color.Red
Else
txtEmail.Text = CType(Email, String)
txtEmail.ForeColor = Color.Black
End If
修改后的代码
If Email Is Nothing Then
txtEmail.Text = "No email on record" ' blank if dbnull values
txtEmail.ForeColor = Color.Red
Else
txtEmail.Text = CType(Email, String)
txtEmail.ForeColor = Color.Black
End If