所以我有一个包含具有visibility
枚举属性的post
对象的列表。我正在尝试获取所有具有visibility == visibility.public
和visibility == visibility.private && AuthorId == currentUserId
的帖子。
这似乎不起作用:from e in list select (e.Visibility == Visibility.Public && (e.Visibility == Visibility.Private && e.Author.Id == userId))
如有任何帮助,将不胜感激
您要求帖子同时具有公共和私有可见性。您的两个条件应该使用OR而不是AND。
您的条件应该是e.Visibility == Visibility.Public || (e.Visibility == Visibility.Private && e.Author.Id == userId)
注意||
试试这个
var filteredList = list.Where(x => x.Visibility == Visibility.Public || (x.Visibility == Visibility.Private && x.AuthorId == currentUserId)).ToList();