大佬教程收集整理的这篇文章主要介绍了c# – Linq从nestes列表中选择peroperty,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
class Controller { public List<Action> Actions {get; set;} } class Action { public int id {get; set; public bool IsSELEcted {get; set;} } List<Controller> controllers = GetControllers(); var toadd = viewmodel.PermissionControllers .Where(x => x.Actions != null) .Where(x => x.Actions.Where(z => z.IsSELEcted)) // i Am having problem there .ToList();
我想获得IEnumerable< int> IsSELEcted的动作设置为true.没有linq它将是:
var ints = new List<int>(); foreach (var controller in controllers) { if (controller.Actions != null) { foreach (var action in Actions) { if (action.IsSELEcted) ints.Add(action.Id); } } }
不幸的是,我被困在哪里.你能帮助我吗?
.Where(x => x.Actions.Where(z => z.IsSELEcted)) // i Am having problem there
你有一个问题,在哪里需要一个bool来确定是否应该包括这个但你提供另一个产生动作而不是一个bool的地方.也许你想要:
List<int> actionIdList = viewmodel.PermissionControllers .Where(x => x.Actions != null) .SELEctMany(x => x.Actions.Where(a => a.IsSELEcted).SELEct(a => a.Id)) .ToList();
以上是大佬教程为你收集整理的c# – Linq从nestes列表中选择peroperty全部内容,希望文章能够帮你解决c# – Linq从nestes列表中选择peroperty所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。