How to Remove multiple items in List using RemoveAll on condition?

前端 未结 4 1498
清酒与你
清酒与你 2021-01-05 12:01

I tried like following.

MyList.RemoveAll(t => t.Name == \"ABS\");
MyList.RemoveAll(t => t.Name == \"XYZ\");
MyList.RemoveAll(t => t.Name == \"APO\")         


        
4条回答
  •  没有蜡笔的小新
    2021-01-05 12:42

    A more extnsible approach would be to have a List for what to remove then

    List toRemove = ...
    MyList.RemoveAll(t =>  toRemove.Contains(t.Name));
    

    where T is a string in your example

提交回复
热议问题