I am somewhat new to Linq XML and enjoy a lot of this. I am currently stuck on the following situation.
- I have an intArray {1, 2, 3}
- I want to obtain values of an element --> i.e. a enumeration.
- 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.
精彩评论