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 ModuleNote: We recommend using List or ArrayList, which are much more efficient for this type of operation. You can view information on this topic.