I don’t usually develop on Windows but recently I have had to do a bit of work with C# and I’m trying to get my head around a few things. I’ve been looking through the MSDN but cant quite find what I’m looking for.
Anyway as I understand it a List is indexed, much like an array. However if I deleted an item at position X using RemoveAt() would it then shift all the items so that a new item now filled position X? Or would position X just be empty?
Also using Remove() seems fairly straight forward if you have a List of strings or integers, but if you have a list of objects is it possible to use Remove() to delete an item where an object field has a specific value?
For example
Say i have List where each car object has a make, model & color.
Could i do something along the lines of
cars.Remove(cars.color="red");
I’m sure that is horribly wrong but I am coming from a PHP background so im pretty confused about alot of the syntax at the moment.
Thanks
List<T>will not get holes.Removing an item will shift all subsequent items up by one.
You can remove all items that match a condition by calling
RemoveAll()with a lambda expression: