6
나는 2 개의 클래스가 있습니다 feeds_Auto 및 제품 여러 개의 일치하는 속성이 있습니다. 이 특정 문제에 대해 AutoID는 내가 사용하는 유일한 필드입니다.C# List <object> .RemoveAll() - 목록의 하위 집합을 제거하는 방법?
나는 List<FeedsAuto>
이고, 수는 이고, 고유 번호는입니다. 내가 작은 List<Product>
10, 20 항목이 있습니다. 이제 큰 목록에서 작은 목록의 모든 항목을 제거하려고합니다.
어떻게 이것을 수행하려면 RemoveAll ({lambda expression})을 사용합니까? 내가 발견 한 모든 예제는 일반 목록이 단순한 유형 (문자열, int 등)에 의존합니다.
private static int DoInserts(ref List<Model.feeds_Auto> source, ref List<Model.Product> target, Guid companyID)
{
List<Model.Product> newProductList = new List<Model.Product>();
List<Model.Product> dropSourceList = new List<Model.Product>();
using (var db = Helpers.GetProdDB())
{
foreach (var src in source)
{
var tgt = target.Where(a => a.alternateProductID == src.AutoID && a.LastFeedUpdate < src.DateModified).FirstOrDefault();
if (tgt == null)
{
newProductList.Add(new Model.Product{...});
dropSourceList.Add(src);
}
}
db.SaveChanges();
if (dropSourceList.Count > 0)
{
source.RemoveAll(????);
}
}
}
루프에서이 작업을 수행하는 것은 어려운 일이 아니다 :
이
foreach (var drop in dropSourceList)
{
source.RemoveAll(a => a.AutoID == drop.AutoID);
}
그냥 각 패스에서 하나 개의 항목에서 removeAll 전화 세트에 루프 (나에게) 이해가되지 않습니다.
감사합니다! 매끄러운 모두가 나가. 오, 람다를 올바르게 사용하는 법을 배워야합니다. :) –