Last active
November 10, 2019 17:03
-
-
Save jouni-kantola/80a3c38246a34f01dbbbafb3d01efb06 to your computer and use it in GitHub Desktop.
Implicitly typed lambda expressions in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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