c# - ERROR: Collection was modified; enumeration operation may not execute. Other solutions are not working for me -


i'm deleteing users in sharepoint site , error. here's code:

foreach (spuser user in users)  {     string user_name = user.loginname;      string[]username = user_name.split('\\');     user_name = username[1].tostring().tolower();       bool exists= checkifexists(user_name);     if (exists != true)     {          users.remove(user.loginname);     } } 

i've read similar issues solutions found not working me since can't use tolist() or toarray() method.

if can't use tolist() or toarray() directly, create new list , add items users it, use new list in foreach loop

though obious users implement ienumerable interface (otherwise wouldn't able use in foreach loop), toarray() preferred way solve problem. maybe can't use toarray() because implementation not generic? in case try users.oftype<spuser>().toarray()


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -