C# language feature:
applies to
benefit
ValueTask<TResult>
. Previously async types were limited to returning void
, Task
, Task<T>
. Use of Task<T>
requires allocating object which hinders performance.how to use
ValueTask<TResult>
as the return type.important note
ValueTask<TResult>
, add NuGet package System.Threading.Tasks.Extensions to your project.example:
public async ValueTask<double> Generalized_Async_Return_Types_Example()
{
await Task.Delay(100);
return 3.14;
}