On Wed, 28 May 2008 01:30:02 -0700, Alberto Poblacion
<ea******************************@poblacion.orgwro te:
"Michael Harrington" <mi*****@bigpond.comwrote in message
news:e4**************@TK2MSFTNGP05.phx.gbl...
>Is there a C# equivalent to Vb6's Erase when dealing with arrays?
If I remember correctly, VB6 Erase removed all elements of an array
and left the array with length zero.
Looking at the docs, it appears to me that Erase simply removes the array
altogether, leaving the identifier unusable until the array is "ReDim"'ed.
In that respect, I think assigning the array to null is closer to the
actual idea the OP has.
However: according to the docs, Erase is strictly a procedure-level
thing. It can only be used on local variables. In C#, assigning a local
variable to null is pointless. The compiler already can tell whether a
local variable is used past some point within the method body, and makes
the object a variable references eligible for garbage collection if that
variable isn't used again within the method. All that assigning to null
does is extend the lifetime of that object to the point where the variable
was assigned to null.
In other words, the correct answer to the OP is very likely: the best
"equivalent" in C# to the Erase statement is to do nothing at all.
Pete