用数组过滤Linq中的IEnumerable [英] Filter an IEnumerable in Linq with an array
本文介绍了用数组过滤Linq中的IEnumerable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何添加字符串数组
string[] BranchIds = {"1","2","3"}
包含在Linq中吗?
我正在寻找的类似东西
var a =_abc.GetRoutes(0).Where(n => n.BranchId.Contains(BranchIds[])).ToList();
这里的BranchId是模型中的字符串
Here the BranchId is a String in the model
推荐答案
您正在尝试检查route的branchId是否包含ID数组(不会编译).您应该执行相反的操作-检查ids数组是否包含路由的branchId:
You are trying to check whether branchId of route contains array of ids (that will not compile). You should do the opposite - check whether ids array contains branchId of route:
var a =_abc.GetRoutes(0).Where(r => BranchIds.Contains(r.BranchId)).ToList();
这篇关于用数组过滤Linq中的IEnumerable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文