Lets say I have this array,
int[] numbers = {1, 3, 4, 9, 2};
How can I delete an element by ‘name’? , lets say number 4?
Even ArrayList didn’t help to delete?
string strNumbers = ' 1, 3, 4, 9, 2'; ArrayList numbers = new ArrayList(strNumbers.Split(new char[] { ',' })); numbers.RemoveAt(numbers.IndexOf(4)); foreach (var n in numbers) { Response.Write(n); }
If you want to remove all instances of 4 without needing to know the index:
LINQ: (.NET Framework 3.5)
Non-LINQ: (.NET Framework 2.0)
If you want to remove just the first instance:
LINQ: (.NET Framework 3.5)
Non-LINQ: (.NET Framework 2.0)
Edit: Just in case you hadn’t already figured it out, as Malfist pointed out, you need to be targetting the .NET Framework 3.5 in order for the LINQ code examples to work. If you’re targetting 2.0 you need to reference the Non-LINQ examples.