Martijn
Martijn

Reputation: 12092

Are the values of array elements defined upon defining an array?

I feel quite silly asking this, but I couldn't find a definite answer anywhere. in vb.net, how are the array elements defined (if they are defined) for, for example:

Dim myarray(5) as int

does, at this point in time, myarray(3) for example have a defined value? If so, what is it?

Upvotes: 2

Views: 61

Answers (1)

Meta-Knight
Meta-Knight

Reputation: 17845

From the MSDN documentation for the Dim statement:

If you declare the length of an array but do not initialize its elements, each element is initialized as if it were a separate variable.

Essentially, value types will be initialized to their default value (0 for numeric types), and reference types will be initialized to Nothing.

Upvotes: 2

Related Questions