请看下面的代码:
Imports System.Data.Common
Imports System.Data.SqlClient
Imports System.Data.OracleClient
Public Class clsParameterValues
Implements IDisposable
Private paramValues(0) As DbParameter
Public Function AssignParameterValues(ByVal strParameterName As String, ByVal strParameterValue As String, ByVal intDatabaseType As Integer) As Integer
Dim intArrayBound As Integer
intArrayBound = UBound(paramValues)
If intArrayBound > 0 Then
ReDim paramValues(intArrayBound)
End If
If intDatabaseType = 1 Then
paramValues(intArrayBound) = New SqlParameter(strParameterName, strParameterValue)
ElseIf intDatabaseType = 2 Then
paramValues(intArrayBound) = New OracleParameter(strParameterName, strParameterValue)
'paramValues(intArrayBound) = New OracleParameter(":" & strParameterName, OracleType.Int32)
'paramValues(intArrayBound).Value = strParameterValue
End If
Return intArrayBound
End Function
Public Function getParameterValues() As DbParameter()
Return paramValues
End Function
Public Sub Dispose() Implements IDisposable.Dispose
Erase paramValues
paramValues = Nothing
End Sub
End Class
网页功能如下所示:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim objParameterValues As New clsParameterValues
Using objParameterValues
'Use the objParameterValues class here.
End Using
objParameterValues=nothing
End Using
End Sub
在IDisposable.Dispose
将数组设置为Nothing
. 我认为这是不好的做法,因为 Array 类没有实现IDisposable
. 甚至有必要擦除一个数组并将其设置为Nothing
吗?(垃圾收集器会处理这个吗?)