Search code examples
arraysvb.neterase

Reset an Array to Default in Visual Basic 2010


What is the code to reset an array to its default state so that all the elements are erased?


Solution

  • you can try Array.Clear method :

    Array.Clear(myArray, 0, myArray.Length)
    

    that will revert value of each array element to default (0, false, or Nothing depending on the element type as described in the link above).

    Another option is to use Erase

    Erase myArray
    

    that will turn myArray variable to Nothing.