我有这段代码的问题,当我做我的相交方法一切工作正常。List.Intersect结果改变后foreach
当我在foreach之前做计数在我的十字路口,我有1
在foreach后,如果在foreach我有0后,再次进行计数,为什么会出现这种情况?它应始终为1 ...
var matchedRoles = roles.Intersect(user.Roles);
int before = matchedRoles.Count();
foreach (var matchedRole in matchedRoles)
{
user.Roles.Remove(matchedRole);
}
int after = matchedRoles.Count();
if (matchedRoles.Any())
{
accountRepository.Update(user);
}
你让我的一天!非常感谢! – Swell