"Brian Underhill via DotNetMonster.com" wrote:
I am trying to delete an element from an array. I have an array of 52
elements and I want to search for an element and delete it. Therefore,
making it an array of 51 elements.
is it just
delete MyArray[i];
any help would be great....thanks
Once you get onto the latest release containing generics, there is a static
method on the Array class called Resize---
int[] myArray = new int[10];
// populate it
int[] myShorterArray = Array.Resize<int>(9);
// you have just truncated the array by one element.
Now, if you read carefully, all this is really doing is re-allocating the
array and copying the appropriate elements into the new array. this is the
same manual process you could have done pre-generics, but this makes it so
much cleaner.
Not to disagree with the other replies- this is just one more way of looking
at it.