Search code examples
vb.netarrayselement

vb.net remove first element from array


One answer is to create a new array that is one element shorter. Are there any other simpler ways to do this?


Solution

  • Here is one way to remove the first element of an array in vb.net.

    dim a(n)
    ...
    for i = 1 to ubound(a)
      a(i-1) = a(i)
      next i
    redim preserve a(ubound(a)-1)
    

    You could make a function for this to remove an arbitrary element of an array (Have a parameter for the initial value of the for loop).