.NET 团队于2025年2月25日发布博文,宣布推出 .NET 10 首个预览版更新,重点改进.NET Runtime、SDK、Libraries 、C#、ASP.NET Core、Blazor 和.NET MAUI 等。
.NET 10 是 .NET 9 的后继版本,将作为长期支持维护 (LTS) 版本提供 3 年的支持。
.NET 10 运行时在 Preview 1 中引入了新特性与性能改进,核心目标之一是降低常用语言特性的抽象开销(如虚方法调用)。为此,JIT 编译器的去虚拟化能力已扩展至数组接口方法,可优化包含虚方法调用的数组遍历代码。此外,JIT 支持对不含 GC 指针的固定大小值类型数组进行栈分配,减少引用类型的内存开销。
另一重要特性是新增对 x64 处理器的 AVX10.2 指令集支持(默认关闭)。由于当前硬件尚未普及,开发者需等待支持 AVX10.2 的 CPU 上市后,通过 System.Runtime.Intrinsics.X86.Avx10v2
类测试新内在函数。
.NET 10 类库新增多项功能:
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();
public static class ISOWeek
{
// 新的重载方法
public static int GetWeekOfYear(DateOnly date);
public static int GetYear(DateOnly date);
public static DateOnly ToDateOnly(int year, int week, DayOfWeek dayOfWeek);
}
OrderedDictionary<TKey,TValue>
的 TryAdd
和 TryGetValue
方法返回条目索引,便于快速定位。public class OrderedDictionary<TKey, TValue>
{
// 新的重载方法
public bool TryAdd(TKey key, TValue value, out int index);
public bool TryGetValue(TKey key, out TValue value, out int index);
}
public static void IncrementValue(OrderedDictionary<string, int> orderedDictionary, string key)
{
// Try to add a new key with value 1.
if (!orderedDictionary.TryAdd(key, 1, out int index))
{
// Key was present, so increment the existing value instead.
int value = orderedDictionary.GetAt(index).Value;
orderedDictionary.SetAt(index, value + 1);
}
}
.NET 10 SDK 引入了以下新功能和增强功能:
从 .NET 10 开始,NuGet Audit 功能现在可以修剪项目中未使用的框架提供的包引用。此功能默认对所有 net 目标框架(例如 net8.0、net10.0)以及 .NET Standard 2.0 及更高版本启用。这一改进减少了构建过程中需要恢复(restore)和分析的包数量,从而可能加快构建速度、减少磁盘空间占用,并降低 NuGet Audit 或其他依赖扫描机制的误报率。
此版本主要针对 .NET MAUI、.NET for Android、.NET for iOS、Mac Catalyst、macOS 和 tvOS 进行了质量改进。
ExecuteUpdateAsync
方法现在支持接受常规的非表达式形式 Lambda(例如包含代码块的语句 Lambda),简化批量更新操作的异步执行代码编写。此更新显著提升了 EF Core 在处理复杂查询。
await context.Blogs.ExecuteUpdateAsync(s =>
{
s.SetProperty(b => b.Views, 8);
if (nameChanged)
{
s.SetProperty(b => b.Name, "foo");
}
});
C# 14 引入了许多新特性和增强功能,以提高开发者的生产力和代码质量。其中一些关键更新包括: