[Help] Deleting Array Element in C#

Hi all i just want to ask question on how to do this deleting both element & value by using code in C#,
i try to use System.Array.Clear(Arr,Indx, Indx Length) but the only deleted is the value of the element.:(:(:frowning:

Thank you in Advance!:(:(:frowning:

What do you mean by delete?

System.Array.Clear empties out that slot in the array.

Do you mean you want to remove the element, then redact that part of the array?

What I mean is… Clear does this:

[a,b,c,d,e]
if you clear (arr, 2, 2) you end up with:
[a,b, , ,e]

Are you expecting to get something like this?
[a,b,e]

If so, array might not be the type you want to use. Look into using List or something like that. It allows for adding and removing elements much more easily.

i want is remove both element and the value on my script. just like on the image i post, once you right click the specific element or index its automatic deleted.

tldr; You can not delete an array element. If you want to do that you must use something like List<> and not an array.

By definition an array is a contiguous block of memory, removing element is simply not possible.

What’s happening in the image you show is that Unity is creating a whole new array for you and populating it with the content you define in the Inspector.

It is not deleting an element from an existing array - that can’t be done.

Ahh Ok so i have no choice to use List<>, i just ask if it’s possible to do it on the code.

Well it’s possible. You’ll have to create a new array of the new length, and copy in the values you don’t want deleted.

But it’s slower, and creates more garbage for the garbage collector. Where as List can do it more efficiently.