.net &引用;使用;对于函数返回的对象

.net &引用;使用;对于函数返回的对象,.net,using,using-statement,.net,Using,Using Statement,我只想在很短的时间内使用SQLite连接 因为我经常为不同的数据库执行此操作,所以我想为其创建一个函数: Public Function ConnectionFromPath(ByVal uDBPath As String) As SQLite.SQLiteConnection Dim nConn As New SQLite.SQLiteConnection With nConn .ConnectionString = "Data source=" &

我只想在很短的时间内使用SQLite连接

因为我经常为不同的数据库执行此操作,所以我想为其创建一个函数:

Public Function ConnectionFromPath(ByVal uDBPath As String) As SQLite.SQLiteConnection

    Dim nConn As New SQLite.SQLiteConnection
    With nConn
        .ConnectionString = "Data source=" & uDBPath
        .Open()
    End With

    Return nConn

End Function
通常,我对SQLite.SQLiteConnection使用“Using…End-Using”

现在我只想说:

Using nCn As SQLite.SQLiteConnection = modDB.ConnectionFromPath(uDBPath)
    'Do something with it
End Using 'This should automatically close the db and free the file

我的函数从SQLite.SQLiteConnection的“可用性”中“继承”了“使用”,还是我遗漏了什么?

这是正确的,我认为你没有遗漏任何东西这是正确的,我认为你没有遗漏任何东西