Why C # Func <interface> lambda expression requires drop for result

I need to understand an expression like Func deeper.

public class TheResult : IResultEntry { ... } 

With the above class, why does the second method require casting ?

I can read the error message, of course, but it's hard to understand.

 // Success public Task<IResultEntry> ProcessAsync_1() { return Task.Factory.StartNew(() => (IResultEntry) new TheResult()); } // Fail: Compiler error. Cannot implicitly convert... public Task<IResultEntry> ProcessAsync_2() { return Task.Factory.StartNew(() => new TheResult()); } 

If we change it to a named method using ReSharper, we can do without translation.

 public Task<IResultEntry> ProcessAsync_2_Changed() { return Task.Factory.StartNew(function); } private IResultEntry function() { return new TheResult(); } 
+8
c # lambda func task-parallel-library
source share

No one has answered this question yet.

See similar questions:

33
Why is Task <T> not a co-option?
8
Casting TResult in Task <TResult> in System.Object

or similar:

2964
How to cast int to enum?
1391
What is a lambda expression in C ++ 11?
891
Why are you using Expression <Func <T>> and not Func <T>?
826
Why is Python lambdas useful?
483
Getting property name from lambda expression
401
Reflection of parameter name: abuse of C # lambda expressions or syntax brilliance?
271
C # lambda expressions: why should they use them?
2
vb.net vs c # lambda expression
one
C # How to use BigInteger with this Lambda expression?
one
task <IList <>> as a result of Func <>

All Articles