Why would one use Task over ValueTask in C#?

As of C# 7.0 async methods can return ValueTask<T>. The explanation says that it should be used when we have a cached result or simulating async via synchronous code. However I still do not understand what is the problem with using ValueTask always or in fact why async/await wasn’t built with a value type from the start. When would ValueTask fail to do the job?

4 Answers
4

Leave a Comment