Best way to remove items from a collection

前端 未结 15 2045
天命终不由人
天命终不由人 2020-12-08 05:47

What is the best way to approach removing items from a collection in C#, once the item is known, but not it\'s index. This is one way to do it, but it seems inelegant at be

15条回答
  •  佛祖请我去吃肉
    2020-12-08 06:43

    If RoleAssignments is a List you can use the following code.

    workSpace.RoleAssignments.RemoveAll(x =>x.Member.Name == shortName);
    

提交回复
热议问题