LINQ identity function

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.

Leave a Comment