Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Delete an item from an array.

$
0
0

I want to delete an item from an array. I thought that it is simple but it is not.

Say 

[2 1 9 4 6 56 4 90 3 4]
int index = Array.IndexOf(array,x);
// to delete x from array
List<string> remain = new List<string>();
remain = array.ToList();
remain.RemoveAt(index);//remove an element

The question is that if I decide to delete "4", there are more "4" in the array. I want more results. We don't know how many "4" are duplicate but I want all.

The above code is only return the first one. 


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>