Remove list element
I have a method which takes a flat list and generates a tree from it. At the end I remove the elements from the list which have been added as a child. This is the part which isn't working anymore and I don't understand why. Meaning when I look at members inside the method, the list at the end is correct, but the actual property still has the deleted elements. The added children are correct though.
4 Replies
You're not removing from the list that is passed into the method
You're removing from the new list you created inside the method
This creates a new list, so the list you passed into this method won't be affected.
Just figured that out as well. Thanks though.
Is there a reason you're doing
members.RemoveAt(members.FindIndex(p => p.Order == member.Order));
instead of members.Remove(member)
?I am trying to think of one and don't find it. I will test it without.