Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lambda expression to grab all values inside a Dictionary

Tags:

c#

lambda

linq

I have a LINQ query which returns all the values inside a Dictionary, conditional upon something:

var apps =
from entry in shape.Decorators
where entry.Value == DecoratorLayoutStyle.App
select entry.Key;

shape.Decorators is a

Dictionary<Shape, DecoratorLayoutStyle>

Is there something terser, and/or can I use a combination of lambdas or something?

like image 672
geejay Avatar asked Aug 07 '26 20:08

geejay


1 Answers

var apps = shape.Decorators
                .Where(x=>x.Value == DecoratorLayoutStyle.App)
                .Select(x=>x.Key);

I think yours is just as fine.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!