![.NET 10 Preview 1]()
.NET 10 is the latest long-term support (LTS) release in the .NET ecosystem, succeeding .NET 9. This release brings significant enhancements across the .NET runtime, libraries, SDK, and various frameworks, further improving performance, usability, and developer productivity.
.NET Runtime Enhancements
Array Interface Method Devirtualization
One of the key optimizations in .NET 10 focuses on reducing the abstraction overhead of popular language features. The JIT compiler now devirtualizes method calls on array interface methods, enabling improved performance.
Consider a simple array summation:
static int Sum(int[] array)
{
int sum = 0;
for (int i = 0; i < array.Length; i++)
{
sum += array[i];
}
return sum;
}
This pattern is easily optimized by the JIT. However, when using an interface:
static int Sum(int[] array)
{
int sum = 0;
IEnumerable<int> temp = array;
foreach (var num in temp)
{
sum += num;
}
return sum;
}
Previously, the JIT could not devirtualize these calls, blocking optimizations like inlining and stack allocation. With .NET 10, these array interface methods are now devirtualized, resulting in performance parity between both implementations.
Stack Allocation of Arrays of Value Types
.NET 9 introduced stack allocation for objects that do not outlive their parent method. .NET 10 extends this to small, fixed-sized arrays of value types without GC pointers.
Example
static void Sum()
{
int[] numbers = {1, 2, 3};
int sum = 0;
for (int i = 0; i < numbers.Length; i++)
{
sum += numbers[i];
}
Console.WriteLine(sum);
}
Since numbers are a small, fixed-size array known at compile time, the JIT will allocate it on the stack, reducing GC overhead and unlocking further optimizations.
Among other stack allocation enhancements, .NET 10 aims to expand this optimization to reference type arrays in future previews.
Improvements in .NET Libraries
.NET 10 expands its library capabilities with new features and API enhancements. Key improvements include:
Finding Certificates By ThumbprintsFinding
A new FindByThumbprint method for certificate handling, allowing hash algorithms beyond SHA-1.
X509Certificate2Collection coll = store.Certificates.FindByThumbprint(HashAlgorithmName.SHA256, thumbprint);
Debug.Assert(coll.Count < 2, "Collection has too many matches, has SHA-2 been broken?");
return coll.SingleOrDefault();
PEM-encoded data from ASCII-encoded files
Support for reading PEM-encoded data from ASCII-encoded files.
byte[] fileContents = File.ReadAllBytes(path);
-char[] text = Encoding.ASCII.GetString(fileContents);
-PemFields pemFields = PemEncoding.Find(text);
+PemFields pemFields = PemEncoding.FindUtf8(fileContents);
-byte[] contents = Base64.DecodeFromChars(text.AsSpan()[pemFields.Base64Data]);
+byte[] contents = Base64.DecodeFromUtf8(fileContents.AsSpan()[pemFields.Base64Data]);
ISOWeek for DateOnly Type
Enhancements to the ISOWeek class now support the DateOnly type.
public static class ISOWeek
{
// New overloads
public static int GetWeekOfYear(DateOnly date);
public static int GetYear(DateOnly date);
public static DateOnly ToDateOnly(int year, int week, DayOfWeek dayOfWeek);
}
String normalization APIs
Unicode string normalization APIs that work with spans of characters.
public static class StringNormalizationExtensions
{
public static int GetNormalizedLength(this ReadOnlySpan<char> source, NormalizationForm normalizationForm = NormalizationForm.FormC);
public static bool IsNormalized(this ReadOnlySpan<char> source, NormalizationForm normalizationForm = NormalizationForm.FormC);
public static bool TryNormalize(this ReadOnlySpan<char> source, Span<char> destination, out int charsWritten, NormalizationForm normalizationForm = NormalizationForm.FormC);
}
Numeric Ordering for String Comparison
A new CompareOptions.NumericOrdering option for numerical string comparison.
StringComparer numericStringComparer = StringComparer.Create(CultureInfo.CurrentCulture, CompareOptions.NumericOrdering);
Console.WriteLine(numericStringComparer.Equals("02", "2"));
// Output: True
foreach (string os in new[] { "Windows 8", "Windows 10", "Windows 11" }.Order(numericStringComparer))
{
Console.WriteLine(os);
}
// Output:
// Windows 8
// Windows 10
// Windows 11
HashSet<string> set = new HashSet<string>(numericStringComparer) { "007" };
Console.WriteLine(set.Contains("7"));
// Output: True
TryAdd and TryGetValue overloads for OrderedDictionary<TKey, TValue>
New TryAdd and TryGetValue overloads for OrderedDictionary<TKey, TValue>, returning an entry index.
public class OrderedDictionary<TKey, TValue>
{
// New overloads
public bool TryAdd(TKey key, TValue value, out int index);
public bool TryGetValue(TKey key, out TValue value, out int index);
}
Allow specifying ReferenceHandler in JsonSourceGenerationOptions
JSON serialization improvements, including ReferenceHandler support in JsonSourceGenerationOptionsAttribute.
SelfReference selfRef = new SelfReference();
selfRef.Me = selfRef;
Console.WriteLine(JsonSerializer.Serialize(selfRef, ContextWithPreserveReference.Default.SelfReference));
// Output: {"$id":"1","Me":{"$ref":"1"}}
[JsonSourceGenerationOptions(ReferenceHandler = JsonKnownReferenceHandler.Preserve)]
[JsonSerializable(typeof(SelfReference))]
internal partial class ContextWithPreserveReference : JsonSerializerContext
{
}
internal class SelfReference
{
public SelfReference Me { get; set; }
}
.NET SDK Enhancements
.NET 10 Preview 1 introduces significant enhancements to the .NET SDK, particularly in package management. One notable feature is the pruning of framework-provided package references. This functionality, enabled by default for .NET TargetFrameworks like net8.0 and net10.0, as well as .NET Standard 2.0 and above, helps reduce unnecessary packages during the build process. Removing unused framework-provided packages leads to faster build times and less disk space usage. Additionally, it minimizes false positives from NuGet Audit and similar tools.
When enabled, this feature simplifies the .deps.json files by automatically removing redundant package references supplied by the .NET Runtime. Users can disable this feature by setting RestoreEnablePackagePruning to false in their project file or Directory.Build.props. However, doing so may trigger warnings like NU1510, which indicate unnecessary direct package references. Addressing these warnings involves either conditioning or removing those references.
ASP.NET Core 10 Enhancements
ASP.NET Core 10 brings a range of updates across various components:
- Blazor: Introduces the RowClass parameter in QuickGrid and enables Blazor script to serve as a static web asset.
- SignalR: New feature enhancements for real-time applications.
- Minimal APIs: Additional capabilities for defining lightweight APIs.
- OpenAPI: Support for generating OpenAPI 3.1 documents and serving them in YAML format.
- Authentication & Authorization: Various improvements to security-related features.
- Miscellaneous: Enhancements in testing apps with top-level statements and a new helper for detecting local URLs.
.NET MAUI Improvements
.NET 10 Preview 1 introduces several quality improvements for .NET MAUI, enhancing its stability and performance across platforms like Android, iOS, Mac Catalyst, macOS, and tvOS.
CollectionView Enhancements for iOS & Mac Catalyst
- .NET 10 enables new handlers for CollectionView and CarouselView by default, improving performance and stability.
- Developers can opt-out and revert to the previous handlers using the following code:
#if IOS || MACCATALYST
builder.ConfigureMauiHandlers(handlers =>
{
handlers.AddHandler<Microsoft.Maui.Controls.CollectionView, Microsoft.Maui.Controls.Handlers.Items.CollectionViewHandler>();
handlers.AddHandler<Microsoft.Maui.Controls.CarouselView, Microsoft.Maui.Controls.Handlers.Items.CarouselViewHandler>();
});
#endif
Entity Framework (EF) Core 10 Enhancements
EF Core 10 introduces several refinements:
- LINQ and SQL translation improvements for better query optimization.
- ExecuteUpdateAsync now supports regular, non-expression lambda parameters.
C# 14: Advancements in Language Features
C# 14 debuts with multiple features enhancing code maintainability and expressiveness:
- nameof support in unbound generics.
- Implicit span conversions for improved memory safety.
- Field-backed properties for better encapsulation.
- Modifiers on simple lambda parameters.
- Experimental feature: String literals in data sections.
If you want to learn more about C# 14, please go through the detailed article: C# 14 - New Features and Updates
Windows Forms Updates
Windows Forms in .NET 10 brings significant clipboard-related updates:
Changes to clipboard serialization and deserialization. Deprecation of certain clipboard APIs. Introduction of new clipboard-related APIs for enhanced data handling.
Conclusion
.NET 10 continues to evolve with improvements across performance, runtime optimizations, library enhancements, and new development features. With long-term support, this release ensures stability for enterprise applications while offering cutting-edge capabilities for modern development needs.