Reputation: 23
Like,
List<string> a = {"a0","a1","a2","a3"};
Using LINQ, how do I take a[2]
and remove it?
Upvotes: 1
Views: 5780
Reputation: 460058
Sounds as if you are looking for the List.RemoveAt
method instead:
a.RemoveAt(2);
Edit:
how can i find out it is the before the last index
So you want to remove the second last instead of the one with index 2, you can use the Count
property to find it. There's absolutely no need to use Linq here:
if(a.Count > 1)
a.RemoveAt(a.Count - 2);
Upvotes: 4