我有以下方法: -
public void AssignGroupRole(int id, int[] selectedGroups, int[] currentGroups)
{
var roleGroups = FindRole(id).Groups;
var roleGroupsCopy = roleGroups;
var securityRole = FindRole(id);
foreach (var group in roleGroupsCopy)
{
if (currentGroups != null)
{
for (int c = 0; c < currentGroups.Count(); c++)
{
if (group.GroupID == currentGroups[c])
{
securityRole.Groups.Remove(group);
}
}
}
}
但我收到一个错误“集合已修改;枚举操作可能无法执行。” 上
foreach (var group in roleGroupsCopy)
关于如何克服这个错误的任何建议?