The IEnumerable
interface is just that, enumerable - it doesn't provide any methods to Add
or Remove
or modify the list at all.
The interface just provides a way to iterate over some items - most implementations that require enumeration will implement IEnumerable
such as List<T>
Why don't you just use your code without the implicit cast to IEnumerable
// Treat this like a list, not an enumerable
List<User> modifiedUsers = new List<User>();
foreach(var u in users)
{
if(u.userId != 1233)
{
// Use List<T>.Add
modifiedUsers.Add(u);
}
}