我想把下面的C#代码转换成VB.NET。
if (dr != null)
dr.Close();
if (con != null && con.State == ConnectionState.Open)
con.Close();
dr = null;
在VB.NET中,我没有找到任何合适的方法或途径来检查OracleDatareader和OracleConnection对象是否为NULL。我如何在VB.NET中解释上述代码?我使用System.Data.OrcleClient命名空间来访问Orcale数据库的数据。
在vb.net中 !=null
成为 IsNot Nothing
和 &&
成为 andAlso
. 我们需要使用AndAlso,才能够像第二条if语句中那样进行短路。最后,我们需要使用AndAlso来获得像第二个if语句中的短路。==
只是 =
.
因此,最终的结果是:
If dr IsNot Nothing Then
dr.Close()
ElseIf con IsNot Nothing AndAlso con.State = ConnectionState.Open then
con.Close()
End If
dr = Nothing