Lambda expression to capture all values ​​within a dictionary

I have a LINQ query that returns all values ​​inside a Dictionary, something conditional:

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

      

shape.Decorators are

Dictionary<Shape, DecoratorLayoutStyle>

      

Is there something patience and / or can I use a combination of lambda or something like that?

+2
c # lambda linq


source to share


5 answers


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

      



I think your truth is beautiful.

+6


source to share


This looks very poor to me, I think you could use extension functions instead of from / select linq syntax, but it wouldn't be too different.



More importantly, I'm not sure if you want terser. The current format is very readable and clearly documents what you are trying to do.

+3


source to share


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

      

Do you think this is the end?

Personally, I prefer the query syntax, when I have more than one LINQ operator, all the operators I use can be translated to it.

+2


source to share


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

      

+1


source to share


Just to be different.

var apps = shape.Decorators.Keys
  .Where(k => shape.Decorators[k] == DecoratorLayoutStyle.App);

      

0


source to share







All Articles
Loading...
X
Show
Funny
Dev
Pics