473,326 Members | 2,655 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Using statements and returns

If I have a function and inside it have something like this
Using Obj1
Using Obj2
Return Value
End Using
End using

The Using statements still know how to handle the dispose and cleanup
correctly dont they? Or do I have to put the return outside of the using
blocks... I was always under the impression you can return inside of them
and it will still dispose as needed... thanks!
Aug 14 '07 #1
4 1612
Yes - "Using" is implemented via a Try/Finally block (and Dispose call)
behind the scenes and will handle this perfectly well.
--
David Anton
http://www.tangiblesoftwaresolutions.com
Convert between VB, C#, and C++
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
"Smokey Grindel" wrote:
If I have a function and inside it have something like this
Using Obj1
Using Obj2
Return Value
End Using
End using

The Using statements still know how to handle the dispose and cleanup
correctly dont they? Or do I have to put the return outside of the using
blocks... I was always under the impression you can return inside of them
and it will still dispose as needed... thanks!
Aug 14 '07 #2
On Aug 14, 12:05 pm, "Smokey Grindel" <nos...@nospam.comwrote:
If I have a function and inside it have something like this

Using Obj1
Using Obj2
Return Value
End Using
End using

The Using statements still know how to handle the dispose and cleanup
correctly dont they? Or do I have to put the return outside of the using
blocks... I was always under the impression you can return inside of them
and it will still dispose as needed... thanks!
Also note you can do this:

Using Obj1, Obj2
Return Value
End Using

I know it's not the answer to your question (as David beat me to
it :-)), I just thought you might like to know if you didn't already.

Thanks,

Seth Rowe

Aug 14 '07 #3
"Smokey Grindel" <no****@nospam.comschrieb:
If I have a function and inside it have something like this
Using Obj1
Using Obj2
Return Value
End Using
End using

The Using statements still know how to handle the dispose and cleanup
correctly dont they?
Yes.

The code equivalent to those the compiler generates for each 'Using' block
basically looks like that:

\\\
Dim Obj As IDisposable
Try
<Contents of the 'Using' block>
Catch
Finally
Obj.Dispose()
End Try
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Aug 14 '07 #4
Errata:
Dim Obj As IDisposable
.... should read 'Dim Obj As <Type implementing 'IDisposable'= ...'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Aug 14 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Carlos Ribeiro | last post by:
Hello all, I'm posting this to the list with the intention to form a group of people interested in this type of solution. I'm not going to spam the list with it, unless for occasional and...
0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
14
by: root | last post by:
Hi group, Apologies in advance if this has been asked somewhere before, but I haven't managed to get anything from the Google archives - I've been getting introductory guides to C++ all day...
24
by: sureshjayaram | last post by:
In some functions where i need to return multiple error codes at multiple places, I use multiple return statements. Say for ex. if (Found == 1) { if (val == -1) return error1; } else { if...
39
by: slogging_away | last post by:
Hi - I'm running Python 2.4.2 (#67, Sep 28 2005, 12:41:11) on win32, and have a script that makes numerous checks on text files, (configuration files), so discrepancies can be reported. The script...
12
by: rAinDeEr | last post by:
Hi, I have a table with 2 columns ** CREATE TABLE test (emp_num DECIMAL(7) NOT NULL,emp_name CHAR(10) NOT NULL) and i have inserted a number of records. ** Now, I want to insert a new...
17
by: Rico | last post by:
Hello, I am in the midst of converting an Access back end to SQL Server Express. The front end program (converted to Access 2003) uses DAO throughout. In Access, when I use recordset.AddNew I...
1
by: MackTheKnife | last post by:
I have the following 3 SQL statements that need to be combined, if possible. The output of one feeds the input of the next. I need to view all of the defined output fields (the output needs to be...
9
by: John | last post by:
Hello all. I am a PHP newbie and am having an issue using the && in an if statement. here is the code: if ($_REQUEST == "1" && date("Y-m-d") < $rowWork) { die("<h1>The earlybird special has...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.