什么是VB.NET等同于“S”C#中使用'块 [英] What is the VB.NET equivalent to C#'s 'using' block

查看:169
本文介绍了什么是VB.NET等同于“S”C#中使用'块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编码在VB.NET。

I am coding in VB.NET.

目前,我附上对象的初始化和使用的try / catch块,然后撕裂下来(部署,紧密在finally块设置为nothing)。问题是,一个C#'使用'块是很容易使用,并会在我的代码清理东西。

Currently, I am enclosing object initialization and usage in a Try/Catch block and then tear it down (dispose, close, set to nothing) in the Finally block. The problem is, a C# 'using' block is so easy to use and would clean things up in my code.

有一个VB.NET等同?或者是我的最后阻止拆除的解决方案的唯一途径。

Is there a VB.NET equivalent? Or is my Finally block tear-down solution the only way?

推荐答案

这是同样的,只是:

Using conn As New SqlConnection
    ....
End Using

这篇关于什么是VB.NET等同于“S”C#中使用'块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆