2

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?

4
  • whats the basic work you want to do? Commented Sep 13, 2011 at 14:13
  • have a function that returns an array of integers, and fills some or all values. In case it is not filled, it should be 0. This seems to be the current behaviour, but I'm not sure if this is explicitly so in the manual, or undefined behaviour that may change at any point in the future. Commented Sep 13, 2011 at 14:20
  • Well by using current line it declare the array with size 5. and if array(3) contain any value then you can fetch it otherwise it gives you nothing. Commented Sep 13, 2011 at 14:23
  • Am I sure (as far as the language manual is concerened) that that value will be 0 if it's not explicitly set? I couldn't find it anywhere Commented Sep 13, 2011 at 14:25

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.