【发布时间】:2012-07-16 08:17:13
【问题描述】:
实际上,它更接近于:
RemoveAll for ObservableCollections?
罢工>
这是我正在使用的代码,但它的可读性不是很好。我可以使用 LINQ 缩短下面的代码,同时仍然具有相同的功能吗?
int index = 0;
int pos = 0;
foreach (var x in HomeViewModel.RecentPatients)
{
if (x.PID == p.PID)
pos = index;
else
index++;
}
HomeViewModel.RecentPatients.RemoveAt(pos);
【问题讨论】:
-
@Adam Houldsworth 来自 List
,我指定了 ObservableCollection Source。 -
这与您之前的问题有何不同? stackoverflow.com/q/11498056/201088
-
@SupaOden 我注意到了,但我无法编辑接近投票。只有在关闭时才投票重新开放。道歉。
-
说起来更像是stackoverflow.com/questions/5118513/…的复制品
-
最好的方法是 HomeViewModel.RecentPatients.Where(p => ... ).ToList().All(i => HomeViewModel.RecentPatients.Remove(i));