Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have tried to innitialize an array all in one step, like this:

 

intArray() = {1, 2, 3, 4, 5}

or

intArray = {1, 2, 3, 4, 5}

 

or many other methods similar. Nothing seems to work. The only way I have managed to populate the elements of the array is:

 

intArray(0) = 1

intArray(1) = 2

intArray(2) = 3

intArray(3) = 4

intArray(4) = 5

 

Is there a more elegant method?

Posted

Does this only work when the array is innitialized? I've tried:

               dataout = {0, 1, 2, 3, 4, 5, 6}
               dataout() = {0, 1, 2, 3, 4, 5, 6}

The first one gives me "Expression expected." at the first curley brace. The second attempt gives me "Number of indices is less than the number of dimensions of the indexed array." and "Expression expected." like before.

Posted

afaik you can only assign an array like that when it's declared.

 

look into Array copying.

 

Class X
 Protected Shared arr As Integer = {0,0,1,2,1,23,5}

 Public Sub New()
   Dim y As Integer()

   y = DirectCast(arr.Clone(), Integer())
   '' or
   ReDim y(arr.Length() - 1)
   arr.CopyTo(y, 0)

 End Sub


End Class

-=splice=-

It's not my fault I'm a Genius!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...