3 ms·
Is that a new C# 6 feature? Cause in C# 5 delegates can't be implicitly typed. Func<string> blah = () => "im a function"; var blah = new Func<string>(
by kozhevnikov 12y ago
Is that a new C# 6 feature? Cause in C# 5 delegates can't be implicitly typed.
Func<string> blah = () => "im a function";
var blah = new Func<string>(() => "im a function");
- Gurkenmaster 12y agoActually C#6 looks more like this: string blah() => "im a function"; Ceylon: String blah() => "im a function"; Coincidence? Just kidding.
- jacabado 12y agoYou just can't do it implicitl because the compiler can't distinguish Func<string> from Expr<Func<string>>. But you can have a generic extension method that returns one of the types and then via inference you can do it implicitly typed. It shoud be something like this in C# 5: public static class Lamb { public static Func<T> da(this Func<T> f) { return f; } } and then: var egocentricFn = Lamb.da(() => "im a function"); I find it really useful not for Func's but for Expressions, as the type declarations can get pretty long.