Remove element of a regular array

前端 未结 15 2198
野性不改
野性不改 2020-11-22 10:06

I have an array of Foo objects. How do I remove the second element of the array?

I need something similar to RemoveAt() but for a regular array.

15条回答
  •  隐瞒了意图╮
    2020-11-22 10:26

    The nature of arrays is that their length is immutable. You can't add or delete any of the array items.

    You will have to create a new array that is one element shorter and copy the old items to the new array, excluding the element you want to delete.

    So it is probably better to use a List instead of an array.

提交回复
热议问题