scope - integer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Fällgreen

    #1

    scope - integer

    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


  • AlanT

    #2
    Re: scope - integer



    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.Sql Client.SqlConne ction(s)
    ' do something
    End Using

    is the same as

    dim sqc as System.Data.Sql Client
    try
    sqc = New System.Data.Sql Client.SqlConne ction(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.

    Comment

    Working...