David Veeneman
David Veeneman

Reputation: 19132

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

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?

Upvotes: 4

Views: 3891

Answers (2)

Cylon Cat
Cylon Cat

Reputation: 7211

bool answer = targetProperties.Any(x => x == "SelectedDate");

Upvotes: 8

user180326
user180326

Reputation:

targetProperties.Contains("SelectedDate") ?

Upvotes: 8

Related Questions