Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINQ query to return whether an item is found in an array?

Tags:

c#

linq

I am learning LINQ, and I am not sure how to write a query to return a boolean indicating whether an item is found in an 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 an item passed in is in the array, and false if it isn't. What would that query look like?

like image 518
David Veeneman Avatar asked Dec 05 '22 01:12

David Veeneman


1 Answers

bool answer = targetProperties.Any(x => x == "SelectedDate");
like image 179
Cylon Cat Avatar answered Dec 08 '22 11:12

Cylon Cat