private void TotalOutcome(List<Prenumerator> prenumerators, List<Publication> publications)
{
foreach (Publication publication in publications)
{
foreach (Prenumerator prenumerator in prenumerators)
{
if (prenumerator.PublicationCode == publication.Code)
{
publication.Earnings += prenumerator.Count * publication.MonthPrice;
}
}
}
}
我怎樣才能將它轉換爲LINQ?我目前的做法是不行的,沒有做任何事情:
publications = (from publication in publications
from prenumerator in prenumerators
where prenumerator.PublicationCode == publication.Code
select publication);
{
publication.Earnings += prenumerator.Count * publication.MonthPrice;
}
);
linq用於查詢數據,而不是修改數據 –
如果您在匿名類中同時選擇'publication'和'prenumerator',您可以在ToList().ForEach()現在就離開它。 – juharr
所以這是不可能的? –