Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the VB.NET equivalent to C#'s 'using' block

Tags:

c#

vb.net

I am coding in VB.NET.

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.

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

like image 628
crackedcornjimmy Avatar asked Sep 02 '10 21:09

crackedcornjimmy


People also ask

Is VB.NET the same as C#?

Though C# and VB.NET are syntactically very different, that is where the differences mostly end. Microsoft developed both of these languages to be part of the same . NET Framework development platform. They are both developed, managed, and supported by the same language development team at Microsoft.

Is VB.NET used anymore?

Even the oldest coding languages such as Classic Asp, VB6, COBOL, FORTRAN, VB.Net, etc. are still in use in few organizations.

Will VB.NET be phased out?

Visual Basic (VB.NET) will continue to be supported by Microsoft. (It's not dead.) The language will no longer have new features added to it.

Is VB.NET a keyword?

A keyword is a reserved word with special meanings in the compiler, whose meaning cannot be changed. Therefore, these keywords cannot be used as an identifier in VB.NET programming such as class name, variable, function, module, etc.


1 Answers

It's the same, it's just:

Using conn As New SqlConnection     .... End Using 
like image 152
Hans Olsson Avatar answered Oct 19 '22 15:10

Hans Olsson