Visual Basic Remove Element from Array

If you want to delete an element of an array in Visual Basic, you need to create a copy of that array (the deleted element) and synchronize it to its original state.

Arrays are inherently "immutable" objects, meaning they cannot be changed. You cannot add or subtract the specified number of elements.

In the code below, the desired element (3rd element, that is, the 2nd index) of the array is removed and the copy of the new version (created with Linq) is replaced with the old version...

Module ModuleTest Sub Main() Dim arr As Integer() = {100, 90, 80, 70, 60} arr = arr.Where(Function(source, index) index <> 2).ToArray() End Sub End Module

Note: We recommend using List or ArrayList, which are much more efficient for this type of operation. You can view information on this topic.



You May Interest

Visual Basic Getting Last Character of String

Visual Basic Reverse Array

Visual Basic Get Now

Visual Basic String Using StartsWith

Visual Basic Non-Restart Check If Application is Open