开发者

Linq XML checking to see element is in list

I am somewhat new to Linq XML and enjoy a lot of this. I am currently stuck on the following situation.

  1. I have an intArray {1, 2, 3}
  2. I want to obtain values of an element --> i.e. a enumeration.
  3. Now I want to make sure that none of the elements in 2 are in the list 1,2,3 or the method will return false.

So:

1 int[] id={151, 150};

2

var anonymousSurveyResponses =
    from response in doc.D开发者_C百科escendants(ns + "SurveyResponse")
    select new
              {
                  QuestionId = response.Element(ns + "intQuestionId").Value,
              };

What I want to do is find the annonymous.surveyResponses.QuestionID contains ANY of the elements in the array initialed in 1.

Any assistance would be greatly appreciated. Thanks.


You could do something like this:

if(anonymousSurveyResponses.Any(x => id.Contains(x))
{
    // Return true since there's an element in id that matches an
    // element of anonymousSurveyResponses (x in this case).

    // Do your logic here.
}

LINQ Any.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜