想象中的照片標籤系統...LINQ查詢使用ALL
public class Photo
{
public IList<Tag> Tags {get;set;}
}
public class Tag
{
public string Name {get;set;}
}
IList<Tag> tags = new [] {
new Tag{Name = "tag1"},
new Tag{Name = "tag2"}
};
IList<Photo> photos = GetAllPhotos();
這行:
var results = //return photos when Photo.Tags contains BOTH tags
是否有一個LINQ操作我可以用它來實現這一目標?
哈哈,你太快了! –
他可能想要標籤名稱上的匹配,儘管...不會做包含對象的比較嗎? – jvenema
@jvenema:編輯。這可能會更好地使Tag實現'IEquatable' –