.NET 7 Preview 7 发布,下一版本进入 RC 阶段


.NET 7 发布了最后一个预览版 Preview 7,在此之后将会进入 RC 阶段。

此版本主要变化包括对 System.LINQ、Unix 文件权限、底层结构、p/Invoke 源代码生成、代码生成和 websocket 的改进。

优化System.LINQ

System.Linq现在包含OrderOrderDescending方法,它们可以根据TIEnumerable进行排序。IQueryable现在也同样提供对此的支持。

用法

此前需要通过引用自身的值来调用OrderBy/OrderByDescending 

var data = new[] { 2, 1, 3 };
var sorted = data.OrderBy(static e => e);
var sortedDesc = data.OrderByDescending(static e => e);

现在支持直接写成:

var data = new[] { 2, 1, 3 };
var sorted = data.Order();
var sortedDesc = data.OrderByDescending();

支持 Unix 文件模式

此前 .NET 没有内置支持获取和设置 Unix 文件权限,这些权限用于控制哪些用户可以读取、写入和执行文件以及目录。而且 P/Invoking 手动调用 syscalls 并不容易,因为有些 syscalls 在不同的发行版上有不同的公开方式。例如,在 Ubuntu 上,你可能要对__xstat进行 Pinvoke,在 Red Hat 上对stat进行 Pinvoke,诸如此类。为此,Preview 7 引入了一个新的枚举:

public enum UnixFileMode
{
None,
OtherExecute, OtherWrite, OtherRead,
GroupExecute, GroupWrite, GroupRead,
UserExecute, UserWrite, UserRead,
 ...
}

用法

// Create a new directory with specific permissions
Directory.CreateDirectory("myDirectory", UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute);

// Create a new file with specific permissions
FileStreamOptions options = new()
{
Access = FileAccess.Write,
Mode = FileMode.Create,
UnixCreateMode =UnixFileMode.UserRead | UnixFileMode.UserWrite,
};
using FileStream myFile = new FileStream("myFile", options);

// Get the mode of an existing file
UnixFileMode mode = File.GetUnixFileMode("myFile");

// Set the mode of an existing file
File.SetUnixFileMode("myFile", UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute);

优化底层struct:支持ref 字段

.NET 7 运行时环境现在完全支持 ByRefLike 类型中的ref字段(即ref struct)。此功能背后包含大量的语言设计,例如改进底层结构。借助此功能,以前需要在运行时环境中进行专门处理的类型(例如Span<T>ReadOnlySpan<T>),现在可以在 C# 中完全实现。

详情查看发布公告。

相關推薦

2023-03-22

429: Scoped Values (Incubator) 432: Record Patterns (Second Preview) 433: Pattern Matching for switch (Fourth Preview) 434: Foreign Function & Memory API (Second Preview) 436: Virtual Threads (Second Preview) 437: Structured Concurrency (Second Incu

2022-10-17

最新候选版本 (RC)发布,该版本已通过 Visual Studio 17.4 Preview 3测试,并在生产环境中得到支持。 点此下载适用于 Windows、macOS 和 Linux 的 .NET 7 RC2。如需在 Visual Studio 系列产品中试用 .NET 7,建议使用预览通道构建。 如果使用 mac

2022-09-16

ps://dotnetchina.gitee.io/furion 准备工作 早就在 .NET7 发布 Preview 版本的时候,Furion 团队就着实进行适配,前前后后耗时4个多月解决了 .NET5 升级到 .NET6、.NET7 的所有问题,保证一套代码兼容 .NET5+,支持现有的所有 Furion 版本升级

2022-07-28

动。 Java 19 只有 7 个新特性: 405: Record Patterns (Preview) 记录模式 422: Linux/RISC-V Port Linux/RISC-V 移植 424: Foreign Function & Memory API (Preview) 外部函数和内存 API  425: Virtual Threads (Preview) 虚拟线

2023-09-15

JSON Cryptography Logging Configuration Peanut Butter .NET 8 已进入 RC 阶段,有兴趣可以下载体验:https://dotnet.microsoft.com/download/

2022-09-21

新版本总共包含 7 个新的 JEP: 405: Record Patterns (Preview) 422: Linux/RISC-V Port 424: Foreign Function & Memory API (Preview) 425: Virtual Threads (Preview) 426: Vector API (Fourth Incubator) 427: Pattern Matching for switch (Thir

2022-05-12

、DateTime、DateTimeOffset 和 TimeOnly 添加微秒和纳秒属性 在 Preview 4 之前,各种日期和时间结构体中,可用的最小时间增量是 Ticks 属性中可用的“tick”。在 .NET 中,一个 tick 是 100ns。此前开发者必须对"tick"值执行计算以确定微秒

2022-07-14

NET 7 发布了第 6 个预览版。 主要变化包括: 改进 Generic Math,方便 API 作者的使用 为 ML.NET 引入新的 Text Classification API,增加了最先进的深度学习技术对于自然语言处理 对源代码生成器的多项改进 用于 Re

2022-06-16

NET 7 发布了第 5 个预览版。 主要变化包括: 改进 Generic Math,方便 API 作者的使用 为 ML.NET 引入新的 Text Classification API,增加了最先进的深度学习技术对于自然语言处理 对源代码生成器的多项改进 用于 Reg

2023-09-15

NET 8 发布了首个 RC。据称 RC 阶段会发布两个版本,正式版将于 2023 年 11 月 14 日至 16 日在 .NET Conf 2023 上推出。.NET 8 是长期支持 (LTS) 版本,将会获得 3 年技术支持。 公告写道,此版本为 Android 和 WASM 引入了全新的 AOT 模式

2022-07-29

QEMU 7.1 首个 RC 版本已发布,稳定版计划在几周后推出。RC 意味着已进入“功能冻结”阶段,即不会增加或删减功能。按照发布计划,在 8 月底推出稳定版之前,每周都会发布 RC 更新。 QEMU 7.1 带来了对 LoongArch 的支持、大量新的

2022-04-15

NET 7 Preview 3 已发布, .NET 7 的第三个预览版包括对可观察性、启动时间、代码生成、GC 区域、Native AOT 编译等方面的增强。 Native AOT 编译 Native AOT 的主要优势在于启动时间、内存使用、访问受限平台(不允许 JIT)以及磁盘

2022-11-19

QEMU 7.2 第二个 RC 版本已发布,稳定版计划在 12 月推出。RC 意味着已进入 “功能冻结” 阶段,即不会增加或删减功能。按照发布计划,在 12 月发布稳定版之前,每周都会发布 RC 更新,目前计划发布 4 个 RC 版本。 QEMU 7.2 新增了

2022-09-15

NET 7 RC 1 发布了, .NET 7 将有两个支持生产的候选版本 (RC), 这是第一个。 下载 .NET 7 Release Candidate 1 .NET 7 RC 1 中的新增功能: 支持在 Windows Server 2019 上默认使用 ICU 库 Windows Server 2019 缺乏 ICU 支持。在 Windows Server 2019 上运