Remove object from generic list by id

前端 未结 6 1421
你的背包
你的背包 2021-02-07 10:50

I have a domain class like this:

public class DomainClass
{
  public virtual string name{get;set;}
  public virtual IList Notes{get;set;}
}
         


        
6条回答
  •  既然无缘
    2021-02-07 11:43

    You can receive an array of items for removing. Than remove them from list in loop. Look at this sample:

    IList list = new List { 1, 2, 3, 4, 5, 1, 3, 5 };
    
    var valuesToRemove = list.Where(i => i == 1).ToArray();
    
    foreach (var item in valuesToRemove)
    {
        list.Remove(item);
    }
    

提交回复
热议问题