I’d like to search in a Collection (which inherit an another Collection) for a property value.
private ObservableCollection<User> userCollection = someData;
public class User
{
public string Username { get; set; }
public ObservableCollection<Department> Memberships { get; set; }
}
public class Department
{
public string Name { get; set; }
}
//I can't use "Contains", because it requires an object of type "Department", but I don't have the object, just the string "Name" (in this case "MyDepartment")
var result = from usr in userCollection where (usr.Memberships.Contains("MyDepartment")) select usr;
Do you have any suggestions?
use IEnumerable.Any to achieve what you want.
For example :