Skip to content

Instantly share code, notes, and snippets.

@jouni-kantola
Last active November 10, 2019 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jouni-kantola/80a3c38246a34f01dbbbafb3d01efb06 to your computer and use it in GitHub Desktop.
Save jouni-kantola/80a3c38246a34f01dbbbafb3d01efb06 to your computer and use it in GitHub Desktop.
Implicitly typed lambda expressions in C#
using System;
public class Program
{
static Func<TSource, TResult> CreateFunction<TSource, TResult>(Func<TSource, TResult> function)
{
return function;
}
public static void Main()
{
Func<string, string> ToLower = (string value) => value.ToLower();
Console.WriteLine(ToLower("Hello world"));
var ToLowerWrappedAnonymousFunction = CreateFunction((string value) => value.ToLower());
Console.WriteLine(ToLowerWrappedAnonymousFunction("Hello world"));
// computer says no :-(
// docs: https://docs.microsoft.com/en-us/dotnet/csharp/implicitly-typed-lambda-expressions
// var ToLowerAnonymousFunction = (string value) => value.ToLower();
// Console.WriteLine(ToLowerAnonymousFunction("Hello world"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment