C# 14 Implicit Span Conversions on .NET 10: Cleaner Span<T> and ReadOnlySpan<T> APIs

Before C# 14, writing high-performance APIs with Span<T> and ReadOnlySpan<T> often pushed extra .AsSpan() calls onto callers—especially when calling extension methods on arrays or relying on generic type inference. C# 14 makes Span<T> and ReadOnlySpan<T> first-class citizens in the language’s conversion and overload-resolution rules, making zero-allocation slice APIs feel as natural as working with arrays or strings.

Editorial illustration of C# 14 implicit Span and ReadOnlySpan conversions on .NET 10

Editorial illustration: C# 14 recognizes conversions between T[], Span<T>, ReadOnlySpan<T>, and string directly in overload resolution and extension receivers.

Summary

  • C# 14 (supported on the .NET 10 SDK and Visual Studio 2026) adds implicit span conversions to the language’s standard implicit conversions, per Microsoft Learn’s What’s new in C# 14.
  • Arrays (T[]), Span<T>, ReadOnlySpan<T>, and string can now convert naturally in more places—including as extension method receivers and during generic type inference—without manual .AsSpan() calls.
  • Limited covariance is supported when converting from T[], Span<T>, or ReadOnlySpan<T> to ReadOnlySpan<U> where element types are covariance-convertible.
  • Because implicit span conversions are now standard implicit conversions, test existing libraries when upgrading <LangVersion> to 14 in case overload resolution selects a span overload over a legacy array or object overload.

Prerequisites: Language vs. SDK vs. IDE

Keep the three layers distinct before adopting this feature:

  • C# 14 (Language): Defines the new standard implicit and explicit span conversions and updated overload-resolution rules, detailed in the Microsoft Learn First-class span types specification.
  • .NET 10 SDK & Runtime: C# 14 is supported on .NET 10 and newer (<TargetFramework>net10.0</TargetFramework>).
  • Visual Studio 2026 (IDE): Ships with .NET 10 and C# 14 compiler/IntelliSense support (or you can use the .NET 10 SDK with VS Code and the C# Dev Kit).

What changed in C# 14

In earlier C# versions, Span<T> and ReadOnlySpan<T> already had user-defined implicit operator conversions from T[] or string. However, because they were treated as user-defined conversions rather than standard language conversions:

  1. Extension methods on ReadOnlySpan<T> did not bind directly to T[]. Calling array.MySpanExtension() failed unless the caller explicitly wrote array.AsSpan().MySpanExtension().
  2. Generic type inference stalled. Passing int[] to a generic method expecting ReadOnlySpan<T> could not infer T cleanly in many signatures.
  3. Conversions did not compose. Chaining a user-defined conversion with an implicit span conversion was blocked.

Per Microsoft Learn’s First-class span types specification, C# 14 promotes these conversions to standard implicit span conversions:

  • T[] → Span<T>
  • T[] → ReadOnlySpan<U> (when T is covariance-convertible to U)
  • Span<T> → ReadOnlySpan<U> (when T is covariance-convertible to U)
  • ReadOnlySpan<T> → ReadOnlySpan<U> (when T is covariance-convertible to U)
  • string → ReadOnlySpan<char>

Practical example: Zero-allocation helpers without .AsSpan()

Consider a helper library targeting net10.0 (C# 14) that counts matching elements or trims tokens without allocating intermediate arrays:

// Requires <TargetFramework>net10.0</TargetFramework> (C# 14)
public static class SpanMetrics
{
    public static int CountAbove<T>(this ReadOnlySpan<T> values, T threshold)
        where T : IComparable<T>
    {
        int count = 0;
        foreach (ref readonly T item in values)
        {
            if (item.CompareTo(threshold) > 0)
            {
                count++;
            }
        }
        return count;
    }
}

public static class Demo
{
    public static void Run()
    {
        int[] scores = [45, 72, 88, 61, 95];

        // In C# 14, int[] binds directly to the ReadOnlySpan<T> extension receiver
        // and infers T = int without calling scores.AsSpan().
        int passing = scores.CountAbove(70);
        Console.WriteLine($"Passing scores: {passing}");
    }
}

In C# 13, scores.CountAbove(70) would not compile without scores.AsSpan().CountAbove(70). In C# 14, the compiler recognizes the implicit span conversion on the extension receiver and infers T as int automatically.

Pair this cleanly with C# 14 extension members or C# 14 field-backed properties when designing clean .NET 10 domain libraries.

Upgrade gotcha: Overload resolution changes

Making span conversions standard implicit conversions means overload resolution now prefers ReadOnlySpan<T> over certain less-specific overloads (such as IEnumerable<T> or object) in scenarios where C# 13 would have picked the non-span overload or flagged an ambiguity.

If you maintain a NuGet library or large enterprise codebase and upgrade <TargetFramework> to net10.0 (which enables C# 14 by default):

  • Run your full test suite immediately after bumping the target framework.
  • Watch for methods overloaded with both T[] / IEnumerable<T> and ReadOnlySpan<T>—especially if one overload has slightly different behavior (for instance, capturing a reference vs. copying a slice).
  • Remember that Span<T> and ReadOnlySpan<T> are still ref struct types: they cannot be boxed to object, stored as fields on regular heap classes, or held across await boundaries in async methods (for async coordination patterns, see using CancellationToken in async C# methods).

Common mistakes

  • Assuming Span<T> can now be stored on the heap or captured in async lambdas. First-class span conversions improve conversions and overload resolution, not ref struct lifetime rules.
  • Using C# 14 span extension receivers in a project still targeting net8.0 or net9.0. Set <TargetFramework>net10.0</TargetFramework> (or a compatible SDK/language version) before relying on C# 14 syntax.
  • Forgetting that Span<T> is invariant while ReadOnlySpan<T> supports limited covariance. You can convert string[] to ReadOnlySpan<object>, but you cannot convert string[] to Span<object> because mutating a Span<object> could corrupt a string[].

Why this matters

For years, .NET library authors hesitated to expose ReadOnlySpan<T>-first APIs because callers found .AsSpan() noisy. C# 14 removes that ergonomic tax, letting application teams adopt span-based parsing, validation, and math helpers without cluttering call sites.

My Take

Implicit span conversions are the quiet hero of C# 14: you do not learn any new keyword, yet your existing array and string code suddenly works seamlessly with modern ReadOnlySpan<T> APIs. Just run your tests when upgrading existing multi-overload libraries to .NET 10 so any shifted overload picks are caught right away.

Conclusion

Target net10.0 with C# 14 to let T[], Span<T>, ReadOnlySpan<T>, and string convert naturally in extension receivers and generic inference, keep Span<T> ref struct lifetime limits in mind, and verify existing overloaded APIs with unit tests after upgrading.

Sources