如何使用 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));
}