What is the best way to clear an array of strings?

后端 未结 7 1362
被撕碎了的回忆
被撕碎了的回忆 2021-02-19 02:13

What is the best way to clear an array of strings?

7条回答
  •  独厮守ぢ
    2021-02-19 03:01

    Wrong way:

    myArray = Nothing 
    

    Only sets the variable pointing to the array to nothing, but doesn't actually clear the array. Any other variables pointing to the same array will still hold the value. Therefore it is necessary to clear out the array.

    Correct Way

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

提交回复
热议问题