Lambda 多个条件从 List中选择对象
我正在使用 C# 选择列表中的一些对象。以下代码正在运行。
public void filterByWork(string work, int precision)
{
workResults = new List<FbUser>();
Array keywords = work.Split(' ');
workResults = userlist.Where(user => user.work != null);
workResults = workResults.Where((user => user.work.Any(wrk => StringExtensions.match(wrk.employer.name, keywords) >= precision)));
}
但如果我想要多个条件怎么办?我可以在某处使用“OR”关键字吗?因为我想选择 wrk.employer.name = "something" 或 wrk.position.name = "something" 的所有对象。怎么能做到这一点呢?
提前致谢!
I 'm using c# to select some objects in a List. The following code is working.
public void filterByWork(string work, int precision)
{
workResults = new List<FbUser>();
Array keywords = work.Split(' ');
workResults = userlist.Where(user => user.work != null);
workResults = workResults.Where((user => user.work.Any(wrk => StringExtensions.match(wrk.employer.name, keywords) >= precision)));
}
But what if i want more than one condition? Can i use the 'OR' keyword somewhere? Because i want to select all objects where the wrk.employer.name = "something" OR wrk.position.name = "something". How can do this?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以简单地使用普通的
||
运算符:You can simply use the normal
||
operator:好吧,您可以只使用 C# 或运算符 (
||
)。Well, you could just use C#s or operator (
||
).