Getting Started

From install to your first composed Result flow in about five minutes. Works on .NET 10 or later, and on .NET Framework 4.7.2 or later and older .NET versions (such as .NET 8 and 9) through .NET Standard 2.0.

1. Install

dotnet add package QuickResult

Or via the Package Manager console: Install-Package QuickResult. The package has zero dependencies and targets .NET 10 and .NET Standard 2.0.

2. Create your first Results

A Result<T> is either a success carrying a value or a failure carrying an IError. Instead of throwing, return the outcome:

using QuickResult;

Result<decimal> GetBalance(string accountId) =>
    accounts.TryGetValue(accountId, out var account)
        ? Result.Success(account.Balance)
        : Result.Failure<decimal>($"Unknown account '{accountId}'");

3. Consume Results with Match

Match forces you to handle both branches — there is no way to "forget" the error path:

var message = GetBalance("ACC-42").Match(
    onSuccess: balance => $"Balance: {balance:C}",
    onFailure: error => $"Sorry: {error.Message}");

On .NET 10 or later with C# 15, a Result<T> is also a C# union of T and IError, so you can switch on it directly and the compiler checks that both cases are handled:

var message = GetBalance("ACC-42") switch
{
    decimal balance => $"Balance: {balance:C}",
    IError error => $"Sorry: {error.Message}"
};

Projects targeting .NET 10 need the .NET 11 SDK and <LangVersion>15</LangVersion>; projects targeting .NET 11 need nothing extra. See the union reference for the details, or the C# unions article for the background.

4. Compose with LINQ

Chain dependent operations with query syntax. Each from unwraps a success; the first failure short-circuits the rest of the query:

var transfer =
    from source in GetBalance(fromId)
    from target in GetBalance(toId)
    from ok in Result.Success(source >= amount)
                     .FailIfFalse("Insufficient funds")
    select ExecuteTransfer(fromId, toId, amount);

5. Mix in async

This is QuickResult's signature feature: async steps drop into the same query without any adapter code. Await the whole query once at the end:

var report =
    from user in FindUser(userId)                  // Result<User>      (sync)
    from orders in FetchOrdersAsync(user)          // Task<Result<...>> (async)
    from summary in Summarize(orders)              // Result<Summary>   (sync)
    select Render(user, summary);

var result = await report;

6. Wrap the untrusted edges

Real codebases meet exceptions and nulls at their boundaries — parsers, HTTP clients, ORMs. Convert them into Results at the edge, then compose safely inside:

// Exceptions become failures
var config = Result.Try(() => File.ReadAllText("app.json"));

// Async exceptions too
var payload = await Result.TryAsync(() => http.GetStringAsync(url));

// Nulls become named failures
var user = Result.FromNullable(await db.FindAsync(id), "User not found");

// Or build a full pipeline: defer, catch, and null-check in one chain
var value = await Result
    .FromAsync(() => service.GetValueAsync(ct))
    .Try()
    .WhenNull("Service returned null");

Where to next?

Something went wrong. This site returns Results, not exceptions — please reload. ✕