I have a object User
and it is the following class:
public class User
{
public int ID { get; set; }
public string Name { get; set; }
}
And I have a IEnumerable<User>
I want to find out if one specific user exists in IEnumerable<User>
, comparing the user by it's ID.
An example:
IList<User> users = GetUsers(); // 1, 2, 3
IEnumerable<User> list = GetList(); // 2, 5, 8
// this doesn't work
list.Contains(users[0].ID); // false
list.Contains(users[1].ID); // true !
list.Contains(users[2].ID); // false
How can I do it? And what is the fastest way to retrieve this boolean, is it Contains?