What is the difference between Task and ValueTask?
Ask by ICSM Computer
Updated 12 Jun 2025
TaskvsValueTaskin C#Both
TaskandValueTaskare used in asynchronous programming in C#, but they serve slightly different performance and resource optimization goals.Quick Summary
TaskValueTaskDetailed Explanation
TaskValueTaskTaskor a result.When to Use
ValueTask(and When Not To)Use
ValueTaskwhen:Avoid
ValueTaskwhen:Key Gotchas
awaitaValueTaskmore than once unless you convert it toTask.ValueTaskintroduces more edge cases around exceptions and cancellation.Example: Task vs ValueTask
Rule of Thumb