开发者

Object Arrays: I have 2 declarations. What's the difference?

Dim MyOrders As Order()
Dim MyO开发者_如何学Pythonrders2() As Order


There is no difference.

The first version (As Order()) is more .Net-style, since Order() is a distinct type.
The second version (MyOrders2() As Order) is a holdover from VB6, which only supported that syntax.

If you declare multiple variables on the same line, there is a difference:

Dim a, b, c As String()  'All three variables are arrays

Dim d(), e, f As String  'Only d is an array


They mean the same thing, it's just two different ways to write it.


As written, there is no difference, but with the second syntax you can also create and size the array like so:

Dim MyOrders(10 - 1) As Order 'creates a 10 element Order array

Note that this of course does not create any Orders


It starts to matter when you do the next thing: create the array.

The VB.NET syntax for creating an array with ten elements:

    Dim MyOrders2(9) As Order

The legacy syntax:

    Dim MyOrders As Order()
    ReDim MyOrders(9)


One day you might come across this

    Dim myBA1 As New BitArray(5)
    'or
    Dim myBA2(5) As BitArray

which used to confused me.

myBA1 is one item with 5 bits myBA2 is an array of 6(Nothing).


I would imagine that if you used Order() you would have that object declared as an array, whereas you might want an array of Orders while an Order is not an array in and of itself...if that makes any sense....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜