简体   繁体   中英

Expression of type 'System.Func`1[System.Threading.Tasks.Task]' cannot be used for return type 'System.Threading.Tasks.Task'

So, I'm using the below assignment:

Expression<Func<Task>> a = Expression.Lambda<Func<Task>>(() => Task.CompletedTask);

And it results in the error mentioned in the thread subject:

Expression of type 'System.Func`1[System.Threading.Tasks.Task]' cannot be used for return type 'System.Threading.Tasks.Task'

I have no idea what I'm doing wrong...

Try removing the Expression.Lambda , compiler should be able to figure out the conversions itself:

Expression<Func<Task>> a = () => Task.CompletedTask;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM