使用linq从列表中删除项目 [英] Remove item from list using linq
本文介绍了使用linq从列表中删除项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用linq从列表中删除项目?
How to remove item from list using linq ?.
我有一个项目列表,每个项目本身都有一个其他项目列表,如果其他项目包含任何已通过列表的项目,我想检查一下,因此应删除主要项目.请检查代码以获得更清晰的信息.
I have a list of items and each item it self having a list of other items now I want to chaeck if other items contains any items of passed list so main item should be remove. Please check code for more clarity.
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));
}
推荐答案
_lstBase
.RemoveAll(a => a.Appointmerts.Any(item => appointmentsToCheck.Contains(item)));
这篇关于使用linq从列表中删除项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文