LINQ query to return if an element is found in an array?

I am learning LINQ, and I'm not sure how to write a query to return a boolean value indicating whether an element is found in the array. I have a very simple list:

var targetProperties = new string[] { "SelectedDate", "SelectedMonth" }; 

I need to write a LINQ query that will return true if the element is passed in an array, and false if it is not. What does this query look like? Thank you for your help.

+4
source share
2 answers
 bool answer = targetProperties.Any(x => x == "SelectedDate"); 
+7
source

targetProperties.Contains("SelectedDate") ?

+8
source

All Articles