我想在一个集合(继承另一个集合)中搜索一个属性值。
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;
你有什么建议吗?