Home All Groups Group Topic Archive Search About
Author
10 Apr 2006 1:48 PM
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

Author
10 Apr 2006 2:51 PM
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.