如何使用linq从列表中删除元素?
我有一个项目列表,每个项目本身都有另一个项目列表,现在我想检查其他项目是否包含传递列表中的任何项目,那么主项目应该被删除。请查看代码以获得更多明确信息。
public Class BaseItems
{
public int ID { get; set; }
public List<IAppointment> Appointmerts { get; set; }
}
Public DeleteApp(List<IAppointment> appointmentsToCheck)
{
List<BaseItems> _lstBase ; // is having list of appointments
//now I want to remove all items from _lstBase which _lstBase.Appointmerts contains
any item of appointmentsToCheck (appointmentsToCheck item and BaseItems.Appointmerts
item is having a same reference)
//_lstBase.RemoveAll(a => a.Appointmerts.Contains( //any item from appointmentsToCheck));
}