I am looking for a way to quickly remove items from a C# List
. The documentation states that the List.Remove()
and List.RemoveAt()<
If you're happy creating a new list, you don't have to go through setting items to null. For example:
// This overload of Where provides the index as well as the value. Unless
// you need the index, use the simpler overload which just provides the value.
List newList = oldList.Where((value, index) => index % 5 != 0)
.ToList();
However, you might want to look at alternative data structures, such as LinkedList
or HashSet
. It really depends on what features you need from your data structure.