I have a method which should return list of Users if the UserId
is in an array. The array of UserIds is passed to the method.
I'm not sure how to write ..where userid in array?
below in ids[]
is clearly not correct.
public List<User> GetUsers(int[] ids)
{
return Users.Values.Where(u => u.UserID in ids[]).ToList();
}
Any ideas how to correct that?
Thanks,
You can try something like that :
public List<User> GetUsers(int[] ids)
{
return Users.Values.Where(u => ids.Contains(u.UserID)).ToList();
}
Alternatively to Quentins answer, use this:
public List<User> GetUsers(int[] ids)
{
return Users.Values.Where(u => ids.Any(x => x == u.UserID)).ToList();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With