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
Youngjae
source shareNo one has answered this question yet.
See similar questions:
33
8
or similar:
2964
1391
891
826
483
401
271
2
one
one