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
geejay
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
Will
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
brien
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
R. Martinho Fernandes
source
to share
var apps = Shape.Decorators.Where(x => x.Value == DecoratorLayoutStyle.App)
.Select(x => x.Key);
+1
Mehrdad afshari
source
to share
Just to be different.
var apps = shape.Decorators.Keys
.Where(k => shape.Decorators[k] == DecoratorLayoutStyle.App);
0
Amy B
source
to share