Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Proper use of the keyword "Using"

Proper use of the keyword "Using"

Scheduled Pinned Locked Moved Visual Basic
csharptutorialquestion
7 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Marcus J Smith
    wrote on last edited by
    #1

    Someone at work told me that you can change code that would normally look like the following:

    Using certainObject as new Object
    Using anotherObject as New Object
    Using somethingElse as new Object

               'Do stuff
    
          End Using
     End Using
    

    End Using

    into this:

    Using certainObject as new Object, _
    anotherObject as New Object, _
    somethingElse as new Object

           'Do stuff
    

    End Using

    I know that VB.NET does something strange when you dimension multiple variables on the same line - ex. Dim str1, str2, str3 as String, I guess Dim str1 as String, str2 as String, str3 as String would be proper. Because of that I am unsure if it is truly proper to format the code with the second code example. Is one more correct than the other or is this just simply a preference thing?


    CleaKO

    "Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)

    P P D L 4 Replies Last reply
    0
    • M Marcus J Smith

      Someone at work told me that you can change code that would normally look like the following:

      Using certainObject as new Object
      Using anotherObject as New Object
      Using somethingElse as new Object

                 'Do stuff
      
            End Using
       End Using
      

      End Using

      into this:

      Using certainObject as new Object, _
      anotherObject as New Object, _
      somethingElse as new Object

             'Do stuff
      

      End Using

      I know that VB.NET does something strange when you dimension multiple variables on the same line - ex. Dim str1, str2, str3 as String, I guess Dim str1 as String, str2 as String, str3 as String would be proper. Because of that I am unsure if it is truly proper to format the code with the second code example. Is one more correct than the other or is this just simply a preference thing?


      CleaKO

      "Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      Don't know about VB, but that won't work in C#.

      1 Reply Last reply
      0
      • M Marcus J Smith

        Someone at work told me that you can change code that would normally look like the following:

        Using certainObject as new Object
        Using anotherObject as New Object
        Using somethingElse as new Object

                   'Do stuff
        
              End Using
         End Using
        

        End Using

        into this:

        Using certainObject as new Object, _
        anotherObject as New Object, _
        somethingElse as new Object

               'Do stuff
        

        End Using

        I know that VB.NET does something strange when you dimension multiple variables on the same line - ex. Dim str1, str2, str3 as String, I guess Dim str1 as String, str2 as String, str3 as String would be proper. Because of that I am unsure if it is truly proper to format the code with the second code example. Is one more correct than the other or is this just simply a preference thing?


        CleaKO

        "Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)

        P Offline
        P Offline
        Paul Conrad
        wrote on last edited by
        #3

        CleaKO wrote:

        is this just simply a preference thing?

        Both are correct and do the same. It is a preference thing.

        "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

        1 Reply Last reply
        0
        • M Marcus J Smith

          Someone at work told me that you can change code that would normally look like the following:

          Using certainObject as new Object
          Using anotherObject as New Object
          Using somethingElse as new Object

                     'Do stuff
          
                End Using
           End Using
          

          End Using

          into this:

          Using certainObject as new Object, _
          anotherObject as New Object, _
          somethingElse as new Object

                 'Do stuff
          

          End Using

          I know that VB.NET does something strange when you dimension multiple variables on the same line - ex. Dim str1, str2, str3 as String, I guess Dim str1 as String, str2 as String, str3 as String would be proper. Because of that I am unsure if it is truly proper to format the code with the second code example. Is one more correct than the other or is this just simply a preference thing?


          CleaKO

          "Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          It's just a matter of preference. They both work the same, though, the nesting gives you a little more readability if you're using multiple objects and need them at different levels.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008

          1 Reply Last reply
          0
          • M Marcus J Smith

            Someone at work told me that you can change code that would normally look like the following:

            Using certainObject as new Object
            Using anotherObject as New Object
            Using somethingElse as new Object

                       'Do stuff
            
                  End Using
             End Using
            

            End Using

            into this:

            Using certainObject as new Object, _
            anotherObject as New Object, _
            somethingElse as new Object

                   'Do stuff
            

            End Using

            I know that VB.NET does something strange when you dimension multiple variables on the same line - ex. Dim str1, str2, str3 as String, I guess Dim str1 as String, str2 as String, str3 as String would be proper. Because of that I am unsure if it is truly proper to format the code with the second code example. Is one more correct than the other or is this just simply a preference thing?


            CleaKO

            "Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            CleaKO wrote:

            Is one more correct than the other

            there is no such thing as "more correct"; a statement is correct or it is not correct. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            Fixturized forever. :confused:


            J 1 Reply Last reply
            0
            • L Luc Pattyn

              CleaKO wrote:

              Is one more correct than the other

              there is no such thing as "more correct"; a statement is correct or it is not correct. :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              Fixturized forever. :confused:


              J Offline
              J Offline
              Jon_Boy
              wrote on last edited by
              #6

              Technically in the example, does Object have a dispose method? :cool:

              Any suggestions, ideas, or 'constructive criticism' are always welcome. "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

              L 1 Reply Last reply
              0
              • J Jon_Boy

                Technically in the example, does Object have a dispose method? :cool:

                Any suggestions, ideas, or 'constructive criticism' are always welcome. "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                kissdznuts wrote:

                does Object have a dispose method?

                No, System.Object does not have a Dispose() method, so it does not implement IDisposable. In C# you could make your own Object class, distinct from System.Object; however in VB.NET that seems not possible. :)

                Luc Pattyn [Forum Guidelines] [My Articles]


                Fixturized forever. :confused:


                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups