Just a little niggle about LINQ syntax. I'm flattening an IEnumerable<IEnumerable<T>>
with SelectMany(x => x)
.
My problem is with the lambda expression x => x
. It looks a bit ugly. Is there some static 'identity function' object that I can use instead of x => x
? Something like SelectMany(IdentityFunction)
?
With C# 6.0 things are getting better. We can define the Identity function in the way suggested by @Sahuagin:
and then use it in
SelectMany
theusing static
constructor:I think it looks very laconic in the such way. I also find Identity function useful when building dictionaries: