Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if values of Dictionary contains an element with certain field value

Tags:

c#

linq

I have a Dictionary

private readonly Dictionary<int, BinaryAssetExtensionDto> _identityMap;

And I would like to do something like this:

if(_identityMap.Values.Contains(x => x.extension == extension))...

Is this possible because previous code doesn't work.

Now I'm doing it like this:

var result = _identityMap.Values.ToList().Find(x => x.extension == extension);
if (result != null) return result;
like image 405
Lieven Cardoen Avatar asked Dec 23 '22 05:12

Lieven Cardoen


1 Answers

using System.Linq;
...
_identityMap.Values.Any(x=>x.extension==extension)
like image 169
Arnis Lapsa Avatar answered Apr 26 '23 15:04

Arnis Lapsa