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)
?
Unless I misunderstand the question, the following seems to work fine for me in C# 4:
public static class Defines
{
public static T Identity<T>(T pValue)
{
return pValue;
}
...
You can then do the following in your example:
var result =
enumerableOfEnumerables
.SelectMany(Defines.Identity);
As well as use Defines.Identity
anywhere you would use a lambda that looks like x => x
.