tags:

views:

424

answers:

3

i have this:

    Dim split As String() = temp_string.Split(",")

    ''#feed all info into global variables
    patient_id = split(0)
    doc_name = split(1)
    lot__no = split(2)
    patient_name = split(3)

how do i clear all the contents of split() ?

+1  A: 
Array.Clear(split, 0, split.Length)
ChaosPandion
+3  A: 

You can always set it to Nothing which will clear the reference. Then the garbage collector will take care of the rest when it finds that to be a good idea.

split = Nothing

However, if this is a local variable of a method you would typically not need to worry about this, the array will be available for garbage collection as soon as it goes out of scope.

Fredrik Mörk
why is your method better than the one below? you are just saying split=nothing?
I__
I would assume that after `Array.Clear`, split will still hold a reference to the (now cleared) array. In my sample it will not reference anything. I would say that in most normal cases the difference will not be noticable (I assume that split is a local variable in a method that goes out of scope when the method is done).
Fredrik Mörk
+1 for "not need to worry about this" There is no good reason to set it to Nothing unless the array itself is a global variable, and that's unlikely.
Joel Coehoorn
+1  A: 
ReDim split(-1)
xpda
why is your method better than the two below
I__
The different in the three methods: redim split(-1)This leaves the array as a string array with zero elements. Array.Clear(split, 0, split.Length)This leaves the array with all it's elements assigned a value of nothing. split = nothingThis leaves split assigned a value of nothing.Which is better? It depends, but sometimes it makes a difference. For example, if you later use ubound to find the upper bound of split, you will get 0, 3, or an error for these three cases.
xpda