Proper use of the keyword "Using"
-
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 guessDim 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)
-
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 guessDim 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)
Don't know about VB, but that won't work in C#.
-
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 guessDim 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)
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
-
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 guessDim 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)
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 -
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 guessDim 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)
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:
-
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:
-
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
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: