Will release the connection as soon as you get out of the using. Actually better than that, ADO.net will keep the connection alive for a few seconds such that if you make another connection to the same server, it reuses connections. I think VB.net still uses reference counting. But it does full garbage collections in addition to that.
(1) The syntax has changed but does the same thing: For Idx = arr.GetLowerBound(0) To arr.GetUpperBound(0).
(2) I don't think VB6's redim preserves the array. It resets it to its default values. You have to use "ReDim Preserve" instead, which has the same behavior in VB6 and VB.net. And I think I remember that either way you can only Redim the last dimension of the array.
I think list feels more natural, I don't see a lot of value in writing explicitly the redim part of the code. I'd rather my code to focus on what I am trying to achieve, not some low level plumbing.
(0) The problem with `Using` is that you can forget to use it. Or you can use it with the wrong object. It's no better than `free()` in C. On the other hand, you when you program in VB6, you can't forget to reference-count your objects, because the language implementation does it for you.
(1) Noted.
(2) I know the difference between `ReDim` and `ReDim Preserve`. And I'm not talking about the array's contents, I'm talking about the array's object identity. In VB6, both `ReDim` and `ReDim Preserve` preserve the array's identity in spite of the size change. .NET arrays don't support resizing at all, so VB.NET hides the limitation by only allowing `ReDim` on local array variables, and implementing it internally in terms of swapping array objects.
And `List` stops being natural when you want it to be multidimensional.
(0) you can forget to call "Dispose" but the benefit of using "using" is that Dispose will get called whichever way you get out of the scope. Using "using" for disposable types ends up being some reflex and it would seem odd to me to see new SqlConnection without a using.
(2) I am not sure I agree with that either. The following in VB6 returns 10, i.e. the second redim has created a new instance of an array:
(0) You can't forget to call “Dispose” if you need objects to be cleaned up in a specific order.
(2) Try this:
Dim V() As Long, W() As Long, i As Long
ReDim V(1 To 10)
For i = LBound(V) To UBound(V)
V(i) = i
Next i
W = V
For i = LBound(W) To UBound(W)
W(i) = 2 * i
Next i
Call MsgBox(V(5))
Call MsgBox(W(5))
Using Cn as new SqlConnection()
End Using
Will release the connection as soon as you get out of the using. Actually better than that, ADO.net will keep the connection alive for a few seconds such that if you make another connection to the same server, it reuses connections. I think VB.net still uses reference counting. But it does full garbage collections in addition to that.
(1) The syntax has changed but does the same thing: For Idx = arr.GetLowerBound(0) To arr.GetUpperBound(0).
(2) I don't think VB6's redim preserves the array. It resets it to its default values. You have to use "ReDim Preserve" instead, which has the same behavior in VB6 and VB.net. And I think I remember that either way you can only Redim the last dimension of the array.
I think list feels more natural, I don't see a lot of value in writing explicitly the redim part of the code. I'd rather my code to focus on what I am trying to achieve, not some low level plumbing.