var listA = ...; var listB = ...; listA.ForEach(m => { var s = listB.FirstOrDefault(n => n.StoreId == m.StoreId); if(s != null) { m.StaffCount = s.StaffCount; } } );
法二:linq查询语法
listA = (from a in listA join b in listB on a.StoreId equas b.StoreId into ab from ba in ab.DefaultIfEmpty(new ModelXXXB()) select new ModelXXXA { StoreId = a.StoreId, OrderCount = a.OrderCount, StaffCount = ba.StaffCount } ).ToList()