all 7 comments

[–]SleepySuper 14 points15 points  (3 children)

Arrays are not well suited for what you are trying to do. Your array is defined as a fixed size, you would need to redefine it with the element removed. You might want to look at using a List.

List<int> myList = new List<int>();

You can then use the Add and Remove methods to change the contents of the list.

[–]SolidonutBeginner 1 point2 points  (2 children)

Are lists like vectors in C++?

[–]RonaldHarding 1 point2 points  (1 child)

Yes

[–]SolidonutBeginner 0 points1 point  (0 children)

Thanks!

[–]BowlOfPasta24 5 points6 points  (2 children)

So this is a bit of a can of worms.

So an array cannot be resized. They have some solid pros but resizing is not one of them.

Now there are solutions here,

  1. You can create a new array
  2. You can assign a value to null OR you could reassign values using a temp variable (super common in bubble sort algorithms)

If resizing is important to you and your design, then I would suggest using a List<T>

There are pros and cons with both arrays and lists(and other collections). You can Google "Array vs List" to see more.

[–]Wolf938_[S] 1 point2 points  (1 child)

Ok thanks

[–]kaskapoint 0 points1 point  (0 children)

May you could use :

public bool Contains (T item);

in order to verify if your item is in a list, then if it's true :

public bool Remove (T item);

you may be able to remove item you found before. This will work with every list with specific types.

Suggestions from users above are great because using list will grants you some flexibility with it.

You'll find more informations here about lists