无法转换类型System.Collections.Generic.IEnumerable<> bool

时间:2016-10-10 09:10:54

标签: c# linq collections

我试图在if条件下对此进行编码:

if (submitAnswersResponseRootObject.Response.SubmitAnswersResult.Prompts.prompt.Where(p=>p.code == 7101))

但我收到错误:

  

无法隐式转换类型   System.Collections.Generic.IEnumerable<> bool

我做错了什么?

2 个答案:

答案 0 :(得分:6)

可能Any代替Where返回其他集合(已过滤)?

if (submitAnswersResponseRootObject.Response.SubmitAnswersResult.Prompts.prompt.Any(p=>p.code == 7101))

答案 1 :(得分:0)

也许是这样的:

  if(submitAnswersResponseRootObject.Response.SubmitAnswersResult.Prompts.
  prompt.Where(p=>p.code == 7101).Any())