I have an ObservableCollection as shown below:
ObservableCollection<Tuple<Guid, string>> _taskCollection
I want to write some code that will check if a given string exists in the collection. The string is held in “TaskName” and the code I wrote looks like this:
_taskCollection.Select(x => x.Item2 == TaskName.Trim()).Any()
The problem I have is that this line of code always returns “true” regardless of whether the value in “TaskName” is in one of the Tuple’s or not. Can anyone show me what I am missing?
You should use
Anydirectly rather than afterSelect:This code:
will return a list of
boolwhich has length equivalent with_taskCollection, so then you callAny, it’s alwaystrue