scope - integer

M

Michael Fällgreen

I like using the "Using Statement" when dealing with objects - you know its
disposed and thereby not in scope further down in the method. But how do you
"make scope" within a method for an int

This is not possible

' i is unknown
Using i as integer
......
end using
' i is unkopwn

you can do

' i is unknown
if true
dim i as integer
.....
end if
' i is unknown

but thats stupid.

How can you make "scope" in a method - it would be nice if this was possible

Scope
....
...
End Scope

Am I missing something?

Thanks
 
A

AlanT

My understanding of the Using statement in VB.Net 2005 is that it
ensures that an object is disposed when you exit the block

Using sqc As New System.Data.SqlClient.SqlConnection(s)
' do something
End Using

is the same as

dim sqc as System.Data.SqlClient
try
sqc = New System.Data.SqlClient.SqlConnection(s)

' do something

finally

sqc.Dispose

end try


You cannot use 'Using' with something that does not implement
IDisposable.


Within C# you can have an 'anonymous' block

e.g.

{
int i = 19;
}

// i is not visible here


but I have not seen anything like that in VB.Net.

hth,
Alan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top