Click to See Complete Forum and Search --> : Array.Clear does not dynamically resize the Array after deletion


kkirtac
August 8th, 2007, 04:52 PM
Hi, i want to dynamically resize my Array's size by deleting the entry of an arbitrary index. my Array contains String^ s.

cli::array<String^,1> files ;

When i use the Clear method of the Array and erase the entry of an index, it just sets Null for that entry but dont decrement the Array's size.
How can i dynamically decrement the Array's size when an entry is deleted ? Here is my piece of code :

for(j=0; j<files->Length; j++)
if( ! ( files->GetValue( j ) ) -> ToString() -> EndsWith( datatype) ) //dataType = "pgm"
files->Clear(files, j, 1);

Here, "files" holds the full pathnames of files in a directory.

Regards,

TheCPUWizard
August 8th, 2007, 05:00 PM
You DONT.

If you did, then the indices of all of items above the one you cleared would change. And this is NOT the expected behavior of the array class.

Sounds like you don't really want an array. Have you looked at a List???

kkirtac
August 8th, 2007, 05:17 PM
Ok, i used ArrayList and the problem is fixed, thank you