How to Return a Finished Task with Task.FromResult in C#
Some methods have to return a Task<T>, because an interface, a delegate or a library says so, yet they already have the answer. Task.FromResult wraps that answer in a task that has already finished, so the method can return it without async and await.
Syntax
Task<<Type>> <task> = Task.FromResult(<value>);
Task<<Type>> <task> = Task.FromResult<<Type>>(<value>);
| Part | What it does |
|---|---|
Task.FromResult(<value>) | A task that's already finished, with <value> as its result |
<Type> | The result's type. C# works it out from <value>, unless you write it in the angle brackets |
Microsoft's Task.FromResult reference: "Creates a Task<TResult> that's completed successfully with the specified result."
The Example
The program makes a finished task holding 3, checks that it's done, and awaits its result. Then a method that must return Task<string> builds a greeting and returns it with Task.FromResult.
Prerequisites
- The .NET 10 SDK or newer, which runs a single
.csfile withdotnet run. This guide uses .NET SDK 10.0.404.
Step 1: Write the Code
Create a file named main.cs in an empty folder:

Task<int> count = Task.FromResult(3);
Console.WriteLine($"Finished already: {count.IsCompleted}");
Console.WriteLine($"Result: {await count}");
Console.WriteLine(await GetGreetingAsync("Ana"));
static Task<string> GetGreetingAsync(string name)
{
return Task.FromResult($"Hello, {name}!");
}
GetGreetingAsync isn't async: it builds the text at once, and Task.FromResult turns it into the Task<string> the method promises.
Step 2: Run It
dotnet run main.cs
Finished already: True
Result: 3
Hello, Ana!

IsCompletedwasTruebefore anything awaited it: the task finished when it was made.await countgave its result, 3, without waiting.- The caller awaits
GetGreetingAsynclike any other task-returning method.
The command is the same in zsh, bash and PowerShell.
Without Task.FromResult
Returning the string itself from the same method doesn't compile:
static Task<string> GetGreetingAsync(string name)
{
return $"Hello, {name}!";
}
/Users/you/demo/main.cs(5,12): error CS0029: Cannot implicitly convert type 'string' to 'System.Threading.Tasks.Task<string>'
The build failed. Fix the build errors and run again.
A string isn't a Task<string>. Either wrap it with Task.FromResult, or mark the method async, which lets it return the string as is.
A Result That's null
To return null as the result, name the type in angle brackets, with ? because it may be null. Task.FromResult(null) alone doesn't build: C# can't tell which type the task holds, and stops with error CS0411.
string? found = await FindNicknameAsync("Ana");
Console.WriteLine(found is null ? "No nickname" : found);
static Task<string?> FindNicknameAsync(string name)
{
return Task.FromResult<string?>(null);
}
No nickname
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Returning the value itself from a non-async Task<T> method | error CS0029: Cannot implicitly convert type 'string' to 'System.Threading.Tasks.Task<string>' | return Task.FromResult(value); |
Task.FromResult(null), without a type | error CS0411: The type arguments for method 'Task.FromResult<TResult>(TResult)' cannot be inferred from the usage. Try specifying the type arguments explicitly. | Task.FromResult<string?>(null) |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
CS0029 ... to 'System.Threading.Tasks.Task<...>' | A plain value returned where a task is expected | Wrap it with Task.FromResult |
CS0411 ... 'Task.FromResult<TResult>(TResult)' cannot be inferred | null alone doesn't say which type the task holds | Name it: Task.FromResult<string?>(null) |
FAQ
Is Task.FromResult the same as Task.CompletedTask?
Task.CompletedTask is a finished task with no result, for methods that return Task. Task.FromResult is for Task<T>, when there's a result to hand back.
Does awaiting a finished task wait?
No. Its result is already there, so await takes it and carries on, as Result: 3 showed.
Conclusion
Task.FromResult(value) gives you a Task<T> that has already finished with value. Use it when a method must return a task but has its answer straight away, and name the type in angle brackets when the value is null.
Additional Resources
- Task.FromResult method, on Microsoft Learn.
- Task-based asynchronous programming, on Microsoft Learn.
