I have code that uses Arrays and, unfortunately, I can't change their types. If I could, I'd use ArrayLists or something simliar to do what I need to do, but I can't. Basically, I'm looking for the best approach to adding and removing objects from a static array. For adding an item to the array on the fly, i have to create a new array that is one element bigger than the old array, copy the items from the old array into the new array, and add the new item. something like this...
public partial class dataStruct
{
private myObject[] myStaticArray;
};
private void AddItemToMyArray()
{
int oldLength = dataStruct.myStaticArray.Length;
myObject[] newMyObjectArray = new myObject[oldLength + 1];
for (int i = 0; i < oldLength; i++)
newMyObjectArray [i] = dataStruct.myStaticArray[i];
dataStruct.myStaticArray[oldLength] = new myObject();
dataStruct.myStaticArray = newMyObjectArray;
}
for deleting an item, i do the same thing, only I create a new array that is one item smaller. this feels really inefficient. can anyone suggest a better approach, if there is one? or any other thoughts?
thanks in advance for all your help!