Reputation: 9611
Trying to do a foreach:
foreach(User in userList)
{
}
Where userList is a IEnumerable<User> userList
I tried doing: userList.ToList() but I get the same message.
Upvotes: 4
Views: 1021
Reputation: 52280
the other answers showed you your syntax problem, but some tool (I think resharper) will warn you that you might enumerate the sequence more than once (maybe even VS - don't know because I use them together). If that is the problem write something like
var userArray = userList.ToArray();
and use userArray instead of userList
Upvotes: 5
Reputation: 86872
A foreach loop requires you to define a variable to place each iteration in. You have only defined the class and are missing the variable.
foreach(User _user in userList)
{
}
Upvotes: 3
Reputation: 112815
In your foreach
statement, you haven't specified an identifier for the current instance of User
. Try adding an identifier (e.g., currUser
or just user
) after the type User
, like this:
foreach(User user in userList)
{
}
Upvotes: 9