草庐IT

whatICareAbout

全部标签

c# - 在通用列表的 ForEach() 的 lambda 表达式中使用条件运算符?

在ForEach的lambda表达式中不允许有条件运算符吗?Listitems=newList{"Item1","Item2","ItemICareAbout"};stringwhatICareAbout="";//doesn'tcompile:(items.ForEach(item=>item.Contains("ICareAbout")?whatICareAbout+=item+",":whatICareAbout+="");编译错误->“只有assignment、call、increment、decrement、new对象表达式才能作为语句使用”尝试使用正常的if也不起作用://