Remove object from generic list by id

前端 未结 6 1419
你的背包
你的背包 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:36

    You could filter out the items you don't want and create a new list with only the items you do want:

    public virtual void RemoveNote(int id)
    {
       //remove the note from the list here
    
       Notes = Notes.Where(note => note.Id != id).ToList();
    }
    

提交回复
热议问题