Remove element from array

hi dudes!

I’m trying to remove an element from an array, though the array I’m using has a different syntax to the one i can find that I found in the manual.

how can i remove an element from this?

Color[] colors = {Color.green,Color.red, Color.white, Color.blue, Color.yellow, Color.black};

Like others have already mentioned, arrays have a fix size. Once created the size can’t be “changed”. However it’s possible to “resize” an array, but it actually creates a new array and copies all values over.

See this SO answer:

public static void RemoveAt<T>(ref T[] arr, int index)
{
    for (int a = index; a < arr.Length - 1; a++)
    {
        // moving elements downwards, to fill the gap at [index]
        arr[a] = arr[a + 1];
    }
    // finally, let's decrement Array's size by one
    Array.Resize(ref arr, arr.Length - 1);
}

RemoveAt(ref colors, 2); // removes Color.white.

Using a generic List is recommended since it only creates a new array if necessary. So if you add / remove a lot elements a List will be better in speed and “garbage production”.

You can’t remove the element from this array in lite, normal, intuitive ways.
Please use
List<Color>
for enabling removing tool

Most people will tell you to use Lists instead, however that’s a cop-out and doesnt really answer the question (but they’re probably right)
if you really need to remove an element from an array, and you can’t use lists or any other libraries, I’m pretty sure the only way is to create a new array and replace the old one with it.
below is an example of a function that you could use to do that

int[] removeAtIndex(int[] inputArray, int index){
 int[] outputArray= new int[inputArray.length-1];
 for(int i=0;i<index;i++){
  outputArray_=inputArray*;*_

}
int writeLoc=index;
int readLoc=index+1;
for(int writeLoc=index;writeLoc<outputArray.Length;writeLoc++){
outputArray[writeLoc]=inputArray[readLoc];
readloc++;
}
return outputArray;
}