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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…