我有以下代码,如果我最后使用conn == null,我仍然使用连接池?我知道关闭连接是一个好习惯但是如何处理整个连接对象?
public void ExecuteNonQuery(SqlCommand Cmd)
{
//========== Connection ==========//
SqlConnection Conn = new SqlConnection(strConStr);
try
{
//========== Open Connection ==========//
Conn.Open();
//========== Execute Command ==========//
Cmd.Connection = Conn;
Cmd.CommandTimeout = 180;
Cmd.ExecuteNonQuery();
}
catch (Exception Exc)
{
throw Exc;
}
finally
{
//======== Closing Connection ========//
if (Conn.State == ConnectionState.Open)
{ Conn.Close(); }
//======== Disposing object ========//
Conn = null;
}
}
Run Code Online (Sandbox Code Playgroud) 在C#中,您不能拥有索引属性.也就是说,如何将以下代码从VB.net转换为C#?
Private _PatchSpectrum(49) As Double
Public ReadOnly Property GetPatchSpectrum() As Double()
Get
Return _PatchSpectrum
End Get
End Property
Public WriteOnly Default Property PatchSpectrum(idx As Integer) As Double
Set(ByVal value as Double)
_PatchSpectrum(idx) = value
End Set
End Property
Run Code Online (Sandbox Code Playgroud)