Introduction
With the release of .NET 10 and C# 14, developers are gaining access to a host of modern features that enhance performance, security, and developer productivity. These updates bring meaningful improvements across the entire .NET ecosystem—from deeper span-based performance optimizations in the base libraries to smarter serialization in web APIs and language enhancements that make your code cleaner and more expressive.
C# 14 Language Enhancements
C# 14 introduces several powerful language features focused on performance, flexibility, and developer convenience. Here are the key updates:
Implicit Span Conversions
C# 14 offers first-class support for the System.Span<T> and System.ReadOnlySpan<T>. These types are designed for high-performance, memory-safe manipulation of contiguous data. C# 14 introduces implicit conversions between.
- T[ ] → Span<T>
- T[ ] → ReadOnlySpan<T>
- Span<T> → ReadOnlySpan<T>
This means you can now write APIs that accept spans and call them with arrays, reducing the need for explicit casts and avoiding unnecessary allocations.
void Print(ReadOnlySpan<char> data)
{
foreach (var ch in data)
Console.Write(ch);
Console.WriteLine();
}
char[] buffer = { 'H', 'e', 'l', 'l', 'o' };
// Implicitly converts char[] to ReadOnlySpan<char>
Print(buffer);
Benefits
- Zero allocations
- Type safety
- Improved performance for memory-intensive operations
Unbound Generic Types in the nameof
Before C# 14, you could only use closed generic types with nameof, such as nameof(List<int>). With C# 14, you can now reference unbound generics in the nameof, enabling cleaner and more flexible metadata or logging scenarios.
Console.WriteLine(nameof(Dictionary<,>));
Console.WriteLine(nameof(List<>));
Output
- Dictionary
- List
Simple Lambda Parameters with Modifiers
C# 14 allows you to use modifiers like ref, out, in, scoped, and ref readonly in lambda parameters, even without specifying the type. Previously, you had to provide full-type declarations to use modifiers.
delegate bool TryParse<T>(string text, out T result);
private static void LambdaParameterModifiersExample()
{
TryParse<int> tryParse = (text, out result) => int.TryParse(text, out result);
if (tryParse("123", out var num))
Console.WriteLine($"Parsed: {num}");
else
Console.WriteLine("Failed to parse");
}
Benefits
- Cleaner syntax
- Better support for modern API design
- Enhanced lambda expressiveness
.NET 10 Library Enhancements
.NET 10 introduces powerful enhancements to its base-class libraries. Here's a breakdown of the most impactful additions.
Finding Certificates by Thumbprint (SHA-2 & SHA-3)
Before .NET 10: Only SHA-1 hash thumbprints were supported, limiting security standards. Now, you can use secure hashing algorithms like SHA-256 or SHA-3 directly.
X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
string thumbprint = "ABCD1234...";
X509Certificate2Collection certs = store.Certificates.FindByThumbprint(HashAlgorithmName.SHA256, thumbprint);
if (certs.Count == 1)
{
Console.WriteLine("Certificate found: " + certs[0].Subject);
}
Join the conversation! Your thoughts help the community grow.