C#高性能开发之类型系统:从 C# 7.0 到 C# 14 的类型系统演进全景
<section id="nice" style="background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); width: auto; font-family: Optima, "Microsoft YaHei", PingFangSC-regular, serif; font-size: 16px; color: rgba(0, 0, 0, 1); line-height: 1.5em; word-spacing: 0; letter-spacing: 0; overflow-wrap: break-word; text-align: left; padding: 0 10px; margin: 0" data-tool="mdnice编辑器" data-website="https://www.mdnice.com"><p style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; text-indent: 0; padding: 16px 0 8px; margin: 0" data-tool="mdnice编辑器">自C# 7.0以来,C#语言在类型系统方面引入了众多新数据类型、类型构造和语言特性,以提升性能、类型安全性和开发效率。本文全面整理了从C# 7.0到C# 14.0(截至2025年4月,C# 14.0为预览版)类型系统的新增内容,包括值元组、<code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">Span<T></code>、<code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">ReadOnlySpan<T></code>、<code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">Memory<T></code>、<code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">ReadOnlyMemory<T></code>、可空引用类型、记录、本机大小整数、记录结构、内联数组,以及其他增强(如只读结构、泛型数学支持)。</p>
<h2 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: flex; flex-direction: unset; float: unset; height: auto; justify-content: center; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 20px; color: rgba(255, 255, 255, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(130, 127, 196, 1); line-height: 1.5em; letter-spacing: 0; align-items: center; border-radius: 30px; box-shadow: none; display: flex; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: center; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 10px; margin: 0; border: 1px none rgba(0, 0, 0, 1)">版本概览</span></h2>
<p style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; text-indent: 0; padding: 16px 0 8px; margin: 0" data-tool="mdnice编辑器">以下是C# 7.0至C# 14.0中类型系统新增或增强的主要内容:</p>
<section class="table-container" style="overflow-x: auto; padding: 0; margin: 0" data-tool="mdnice编辑器">
<table style="display: table; text-align: left">
<thead>
<tr>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">C# 版本</th>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">新增/增强内容</th>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">发布年份</th>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">描述</th>
</tr>
</thead>
<tbody style="font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: normal; border-image: initial; border: 0">
<tr style="color: rgba(63, 63, 63, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(255, 255, 255, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">7.0</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">值元组(Value Tuples)</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">2017</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">轻量级数据结构,支持多值返回和解构</td>
</tr>
<tr style="color: rgba(0, 0, 0, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(248, 248, 248, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">7.2</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">Span, ReadOnlySpan, 只读结构, 引用结构</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">2017</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">高性能内存操作和不可变/栈分配结构体</td>
</tr>
<tr style="color: rgba(63, 63, 63, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(255, 255, 255, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">8.0</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">可空引用类型, Memory, ReadOnlyMemory</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">2019</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">空值安全性和托管内存块</td>
</tr>
<tr style="color: rgba(0, 0, 0, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(248, 248, 248, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">9.0</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">记录, 本机大小整数, 初始化器专用类型</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">2020</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">值语义引用类型、本机整数和不可变属性</td>
</tr>
<tr style="color: rgba(63, 63, 63, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(255, 255, 255, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">10.0</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">记录结构, 全局 using 指令</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">2021</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">值类型记录和简化类型引用</td>
</tr>
<tr style="color: rgba(0, 0, 0, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(248, 248, 248, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">11.0</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">必需成员, 泛型数学支持, 文件局部类型</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">2022</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">强制初始化、泛型运算和类型作用域限制</td>
</tr>
<tr style="color: rgba(63, 63, 63, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(255, 255, 255, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">12.0</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">内联数组</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">2023</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">固定大小数组结构,优化性能</td>
</tr>
<tr style="color: rgba(0, 0, 0, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(248, 248, 248, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">13.0</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">参数集合扩展, 引用结构接口支持, 部分属性</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">2024</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">扩展params、ref struct接口和部分属性定义</td>
</tr>
<tr style="color: rgba(63, 63, 63, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(255, 255, 255, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">14.0</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px"><code>field</code> 关键字, 隐式 span 转换, <code>nameof</code> 增强, lambda 参数修饰符, partial 成员扩展, 空条件赋值</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">2025</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">增强属性访问、span 使用、泛型处理、lambda 表达、partial 类型和空值处理</td>
</tr>
</tbody>
</table>
</section>
<blockquote class="custom-blockquote multiquote-1" style="border-radius: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(251, 249, 253, 1); width: auto; height: auto; box-shadow: 0 0 rgba(0, 0, 0, 0); display: block; overflow-x: auto; overflow-y: auto; border-top: 3px none rgba(0, 0, 0, 0.4); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px solid rgba(53, 179, 120, 1); padding: 10px 10px 10px 20px; margin: 20px 0" data-tool="mdnice编辑器">
<p style="text-indent: 0; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal; padding: 16px 0 8px; margin: 0">以下按版本逐一详述,每节包含特性表格、代码示例和分析。</p>
</blockquote>
<h2 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: flex; flex-direction: unset; float: unset; height: auto; justify-content: center; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 20px; color: rgba(255, 255, 255, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(130, 127, 196, 1); line-height: 1.5em; letter-spacing: 0; align-items: center; border-radius: 30px; box-shadow: none; display: flex; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: center; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 10px; margin: 0; border: 1px none rgba(0, 0, 0, 1)">C# 7.0:值元组</span></h2>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">特性表格</span></h3>
<section class="table-container" style="overflow-x: auto; padding: 0; margin: 0" data-tool="mdnice编辑器">
<table style="display: table; text-align: left">
<thead>
<tr>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">类型/构造</th>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">描述</th>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">主要用途</th>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">注意事项</th>
</tr>
</thead>
<tbody style="font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: normal; border-image: initial; border: 0">
<tr style="color: rgba(63, 63, 63, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(255, 255, 255, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">值元组 (Value Tuples)</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">轻量级值类型,支持多值返回、命名元素和解构</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">方法返回多个值、临时数据分组</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">值类型,栈分配;.NET Framework需引用System.ValueTuple包</td>
</tr>
</tbody>
</table>
</section>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">概述</span></h3>
<p style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; text-indent: 0; padding: 16px 0 8px; margin: 0" data-tool="mdnice编辑器">值元组基于<code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">System.ValueTuple</code>,允许方法返回多个值,支持命名元素和解构,简化数据传递。</p>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">语法</span></h3>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">声明:<code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">(type1, type2, ...) tupleName = (value1, value2, ...);</code></section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">命名元素:<code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">(type1 name1, type2 name2, ...) tupleName = (value1, value2, ...);</code></section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">解构:<code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">var (var1, var2, ...) = tupleName;</code></section>
</li>
</ul>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">示例代码</span></h3>
<pre class="language-csharp highlighter-hljs"><code>public (int id, string name) GetPerson()
{
return (1, "Alice");
}
var person = GetPerson();
Console.WriteLine($"ID: {person.id}, Name: {person.name}");
// 解构
var (id, name) = GetPerson();
Console.WriteLine($"ID: {id}, Name: {name}");</code></pre>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">适用场景</span></h3>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">方法返回多个相关值。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">临时数据分组,无需定义类或结构。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">解构赋值,简化代码。</section>
</li>
</ul>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">注意事项</span></h3>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">值类型,适合轻量数据。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">.NET Framework项目需引用System.ValueTuple NuGet包。</section>
</li>
</ul>
<h2 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: flex; flex-direction: unset; float: unset; height: auto; justify-content: center; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 20px; color: rgba(255, 255, 255, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(130, 127, 196, 1); line-height: 1.5em; letter-spacing: 0; align-items: center; border-radius: 30px; box-shadow: none; display: flex; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: center; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 10px; margin: 0; border: 1px none rgba(0, 0, 0, 1)">C# 7.2:Span, ReadOnlySpan, 只读结构, 引用结构</span></h2>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">特性表格</span></h3>
<section class="table-container" style="overflow-x: auto; padding: 0; margin: 0" data-tool="mdnice编辑器">
<table style="display: table; text-align: left">
<thead>
<tr>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">类型/构造</th>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">描述</th>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">主要用途</th>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">注意事项</th>
</tr>
</thead>
<tbody style="font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: normal; border-image: initial; border: 0">
<tr style="color: rgba(63, 63, 63, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(255, 255, 255, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">Span</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">表示连续内存块的引用,支持读写</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">高性能数组/内存操作</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">ref struct,栈分配,生命周期限制</td>
</tr>
<tr style="color: rgba(0, 0, 0, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(248, 248, 248, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">ReadOnlySpan</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">只读连续内存块引用</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">高性能只读操作</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">同上,需确保内存边界安全</td>
</tr>
<tr style="color: rgba(63, 63, 63, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(255, 255, 255, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">只读结构 (readonly struct)</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">不可变结构体,优化性能</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">不可变数据结构</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">所有实例字段必须只读</td>
</tr>
<tr style="color: rgba(0, 0, 0, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(248, 248, 248, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">引用结构 (ref struct)</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">栈分配结构体</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">高性能内存管理</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">不可boxing或作为接口实现</td>
</tr>
</tbody>
</table>
</section>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">概述</span></h3>
<p style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; text-indent: 0; padding: 16px 0 8px; margin: 0" data-tool="mdnice编辑器"><code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">Span<T></code>和<code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">ReadOnlySpan<T></code>是高性能值类型,表示连续内存块引用,适合数组和本机内存操作。<code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">readonly struct</code>确保结构体不可变,<code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">ref struct</code>限制为栈分配,支持<code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">Span<T></code>等类型。</p>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">语法</span></h3>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">Span: <code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">Span<T> span = collection.AsSpan();</code></section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">ReadOnlySpan: <code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">ReadOnlySpan<T> readOnlySpan = collection.AsSpan();</code></section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">只读结构: <code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">readonly struct StructName { ... }</code></section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">引用结构: <code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">ref struct StructName { ... }</code></section>
</li>
</ul>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">示例代码</span></h3>
<pre class="language-csharp highlighter-hljs"><code>// Span<T> 和 ReadOnlySpan<T>
int[] numbers = ;
Span<int> span = numbers.AsSpan(1, 3);
span = 10;
Console.WriteLine(string.Join(", ", span.ToArray())); // 10, 3, 4
ReadOnlySpan<char> text = "Hello".AsSpan();
Console.WriteLine(text.Slice(0, 2).ToString()); // He
// 只读结构
readonly struct Point
{
public int X { get; init; }
public int Y { get; init; }
}
Point point = new() { X = 1, Y = 2 };
Console.WriteLine($"({point.X}, {point.Y})"); // (1, 2)
// 引用结构
ref struct Buffer
{
public Span<int> Data;
public Buffer(Span<int> data) => Data = data;
}
Buffer buffer = new(numbers.AsSpan());
buffer.Data = 10;
Console.WriteLine(numbers); // 10</code></pre>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">适用场景</span></h3>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">高性能字符串解析、缓冲区处理。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">不可变数据结构(只读结构)。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">避免堆分配(引用结构)。</section>
</li>
</ul>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">注意事项</span></h3>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal"><code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">Span<T></code>和<code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">ReadOnlySpan<T></code>不可用于异步方法。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal"><code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">ref struct</code>限制严格,需管理生命周期。</section>
</li>
</ul>
<h2 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: flex; flex-direction: unset; float: unset; height: auto; justify-content: center; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 20px; color: rgba(255, 255, 255, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(130, 127, 196, 1); line-height: 1.5em; letter-spacing: 0; align-items: center; border-radius: 30px; box-shadow: none; display: flex; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: center; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 10px; margin: 0; border: 1px none rgba(0, 0, 0, 1)">C# 8.0:可空引用类型, Memory, ReadOnlyMemory</span></h2>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">特性表格</span></h3>
<section class="table-container" style="overflow-x: auto; padding: 0; margin: 0" data-tool="mdnice编辑器">
<table style="display: table; text-align: left">
<thead>
<tr>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">类型/构造</th>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">描述</th>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">主要用途</th>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">注意事项</th>
</tr>
</thead>
<tbody style="font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: normal; border-image: initial; border: 0">
<tr style="color: rgba(63, 63, 63, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(255, 255, 255, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">可空引用类型</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">引用类型可标记为可空,默认非null</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">增强空值安全性</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">需启用可空上下文,处理编译器警告</td>
</tr>
<tr style="color: rgba(0, 0, 0, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(248, 248, 248, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">Memory</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">托管内存块,支持读写</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">异步和高性能内存操作</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">适合异步场景,需管理生命周期</td>
</tr>
<tr style="color: rgba(63, 63, 63, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(255, 255, 255, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">ReadOnlyMemory</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">只读托管内存块</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">只读异步内存操作</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">同上</td>
</tr>
</tbody>
</table>
</section>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">概述</span></h3>
<p style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; text-indent: 0; padding: 16px 0 8px; margin: 0" data-tool="mdnice编辑器">可空引用类型通过<code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">?</code>后缀指定引用类型是否可为null,减少空引用异常。<code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">Memory<T></code>和<code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">ReadOnlyMemory<T></code>表示托管内存块,支持异步场景。</p>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">语法</span></h3>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">可空引用类型: <code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">string? nullable; string nonNullable;</code></section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">Memory: <code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">Memory<T> memory = collection.AsMemory();</code></section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">ReadOnlyMemory: <code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">ReadOnlyMemory<T> readOnlyMemory = collection.AsMemory();</code></section>
</li>
</ul>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">示例代码</span></h3>
<pre class="language-csharp highlighter-hljs"><code>// 可空引用类型
#nullable enable
string nonNullable = "Hello";
string? nullable = null;
if (nullable != null)
{
Console.WriteLine(nullable.Length);
}
// Memory<T> 和 ReadOnlyMemory<T>
int[] numbers = ;
Memory<int> memory = numbers.AsMemory(1, 3);
Span<int> span = memory.Span;
span = 10;
Console.WriteLine(string.Join(", ", memory.ToArray())); // 10, 3, 4
ReadOnlyMemory<char> text = "Hello".AsMemory();
Console.WriteLine(text.Slice(0, 2).Span.ToString()); // He</code></pre>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">适用场景</span></h3>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">增强空值安全性(可空引用类型)。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">异步内存操作(Memory)。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">只读数据传递(ReadOnlyMemory)。</section>
</li>
</ul>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">注意事项</span></h3>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">可空引用类型需显式启用。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">Memory生命周期需管理。</section>
</li>
</ul>
<h2 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: flex; flex-direction: unset; float: unset; height: auto; justify-content: center; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 20px; color: rgba(255, 255, 255, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(130, 127, 196, 1); line-height: 1.5em; letter-spacing: 0; align-items: center; border-radius: 30px; box-shadow: none; display: flex; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: center; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 10px; margin: 0; border: 1px none rgba(0, 0, 0, 1)">C# 9.0:记录, 本机大小整数, 初始化器专用类型</span></h2>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">特性表格</span></h3>
<section class="table-container" style="overflow-x: auto; padding: 0; margin: 0" data-tool="mdnice编辑器">
<table style="display: table; text-align: left">
<thead>
<tr>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">类型/构造</th>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">描述</th>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">主要用途</th>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">注意事项</th>
</tr>
</thead>
<tbody style="font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: normal; border-image: initial; border: 0">
<tr style="color: rgba(63, 63, 63, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(255, 255, 255, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">记录 (Records)</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">具有值语义的引用类型,默认不可变</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">数据建模,值相等性</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">默认不可变,可添加可变行为</td>
</tr>
<tr style="color: rgba(0, 0, 0, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(248, 248, 248, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">本机大小整数 (nint, nuint)</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">本机大小整数,映射IntPtr/UIntPtr</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">本机代码互操作</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">平台依赖,需考虑兼容性</td>
</tr>
<tr style="color: rgba(63, 63, 63, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(255, 255, 255, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">初始化器专用类型 (init-only setters)</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">初始化后不可变属性</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">不可变数据模型</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">仅初始化时可赋值</td>
</tr>
</tbody>
</table>
</section>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">概述</span></h3>
<p style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; text-indent: 0; padding: 16px 0 8px; margin: 0" data-tool="mdnice编辑器">记录是具有值语义的引用类型,自动实现相等性。<code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">nint</code>和<code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">nuint</code>支持本机大小整数。<code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">init</code>修饰符增强属性不可变性。</p>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">语法</span></h3>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">记录: <code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">public record ClassName(type1 Property1, ...);</code></section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">本机大小整数: <code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">nint nativeInt; nuint nativeUInt;</code></section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">init-only: <code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">public type Property { get; init; }</code></section>
</li>
</ul>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">示例代码</span></h3>
<pre class="language-csharp highlighter-hljs"><code>// 记录
public record Person(string FirstName, string LastName);
var person1 = new Person("Alice", "Smith");
var person2 = new Person("Alice", "Smith");
Console.WriteLine(person1 == person2); // True
var person3 = person1 with { LastName = "Johnson" };
Console.WriteLine(person3); // Person { FirstName = Alice, LastName = Johnson }
// 本机大小整数
nint nativeInt = 42;
nuint nativeUInt = 42u;
Console.WriteLine($"Native int: {nativeInt}, Native uint: {nativeUInt}");
// 初始化器专用类型
public class Student
{
public string Name { get; init; }
}
var student = new Student { Name = "Alice" };
Console.WriteLine(student.Name); // Alice</code></pre>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">适用场景</span></h3>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">数据传输对象(记录)。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">本机代码互操作(nint, nuint)。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">不可变数据模型(init-only)。</section>
</li>
</ul>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">注意事项</span></h3>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">记录支持继承,需保持值语义。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">本机大小整数平台依赖。</section>
</li>
</ul>
<h2 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: flex; flex-direction: unset; float: unset; height: auto; justify-content: center; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 20px; color: rgba(255, 255, 255, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(130, 127, 196, 1); line-height: 1.5em; letter-spacing: 0; align-items: center; border-radius: 30px; box-shadow: none; display: flex; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: center; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 10px; margin: 0; border: 1px none rgba(0, 0, 0, 1)">C# 10.0:记录结构, 全局 using 指令</span></h2>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">特性表格</span></h3>
<section class="table-container" style="overflow-x: auto; padding: 0; margin: 0" data-tool="mdnice编辑器">
<table style="display: table; text-align: left">
<thead>
<tr>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">类型/构造</th>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">描述</th>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">主要用途</th>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">注意事项</th>
</tr>
</thead>
<tbody style="font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: normal; border-image: initial; border: 0">
<tr style="color: rgba(63, 63, 63, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(255, 255, 255, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">记录结构 (Record Structs)</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">值类型的记录,结合值语义和性能</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">小型数据结构</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">值类型,复制成本需考虑</td>
</tr>
<tr style="color: rgba(0, 0, 0, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(248, 248, 248, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">全局 using 指令</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">全局导入命名空间</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">简化类型引用</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">需平衡代码可读性</td>
</tr>
</tbody>
</table>
</section>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">概述</span></h3>
<p style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; text-indent: 0; padding: 16px 0 8px; margin: 0" data-tool="mdnice编辑器">记录结构将记录特性扩展到值类型,结合值语义和性能。全局<code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">using</code>简化类型引用。</p>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">语法</span></h3>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">记录结构: <code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">public record struct StructName(type1 Property1, ...);</code></section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">全局 using: <code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">global using System;</code></section>
</li>
</ul>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">示例代码</span></h3>
<pre class="language-csharp highlighter-hljs"><code>// 记录结构
public record struct Point(int X, int Y);
var point1 = new Point(1, 2);
var point2 = new Point(1, 2);
Console.WriteLine(point1 == point2); // True
var point3 = point1 with { X = 3 };
Console.WriteLine(point3); // Point { X = 3, Y = 2 }
// 全局 using(假设已在文件顶部)
Console.WriteLine("Hello, World!"); // 无需显式 using System</code></pre>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">适用场景</span></h3>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">值类型数据建模(记录结构)。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">大型项目命名空间管理(全局 using)。</section>
</li>
</ul>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">注意事项</span></h3>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">记录结构复制成本需关注。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">全局 using 需谨慎使用。</section>
</li>
</ul>
<h2 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: flex; flex-direction: unset; float: unset; height: auto; justify-content: center; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 20px; color: rgba(255, 255, 255, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(130, 127, 196, 1); line-height: 1.5em; letter-spacing: 0; align-items: center; border-radius: 30px; box-shadow: none; display: flex; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: center; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 10px; margin: 0; border: 1px none rgba(0, 0, 0, 1)">C# 11.0:必需成员, 泛型数学支持, 文件局部类型</span></h2>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">特性表格</span></h3>
<section class="table-container" style="overflow-x: auto; padding: 0; margin: 0" data-tool="mdnice编辑器">
<table style="display: table; text-align: left">
<thead>
<tr>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">类型/构造</th>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">描述</th>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">主要用途</th>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">注意事项</th>
</tr>
</thead>
<tbody style="font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: normal; border-image: initial; border: 0">
<tr style="color: rgba(63, 63, 63, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(255, 255, 255, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">必需成员 (required members)</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">强制成员初始化</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">确保关键字段初始化</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">需配合初始化器或构造函数</td>
</tr>
<tr style="color: rgba(0, 0, 0, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(248, 248, 248, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">泛型数学支持</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">静态抽象接口成员支持泛型运算</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">泛型算法库</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">需运行时支持(.NET 7+)</td>
</tr>
<tr style="color: rgba(63, 63, 63, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(255, 255, 255, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">文件局部类型 (file modifier)</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">限制类型作用域至文件</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">隔离辅助类型</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">仅限文件作用域</td>
</tr>
</tbody>
</table>
</section>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">概述</span></h3>
<p style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; text-indent: 0; padding: 16px 0 8px; margin: 0" data-tool="mdnice编辑器"><code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">required</code>修饰符强制成员初始化。泛型数学支持通过接口实现数值运算。<code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">file</code>修饰符限制类型作用域。</p>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">语法</span></h3>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">必需成员: <code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">public required type Property { get; set; }</code></section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">泛型数学: <code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">interface INumber<T> { static abstract T operator +(T, T); }</code></section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">文件局部类型: <code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">file class ClassName { ... }</code></section>
</li>
</ul>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">示例代码</span></h3>
<pre class="language-csharp highlighter-hljs"><code>// 必需成员
public class Person
{
public required string Name { get; set; }
}
var person = new Person { Name = "Alice" };
Console.WriteLine(person.Name); // Alice
// 泛型数学支持
public interface INumber<T> where T : INumber<T>
{
static abstract T Add(T left, T right);
}
public readonly struct MyNumber : INumber<MyNumber>
{
public int Value { get; init; }
public MyNumber(int value) => Value = value;
public static MyNumber Add(MyNumber left, MyNumber right) => new(left.Value + right.Value);
}
MyNumber a = new(1);
MyNumber b = new(2);
var result = MyNumber.Add(a, b);
Console.WriteLine(result.Value); // 3
// 文件局部类型
file class Helper
{
public static void Log(string message) => Console.WriteLine(message);
}
Helper.Log("Test");</code></pre>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">适用场景</span></h3>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">API 设计(必需成员)。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">泛型数值计算(泛型数学)。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">代码生成(文件局部类型)。</section>
</li>
</ul>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">注意事项</span></h3>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">必需成员需明确初始化。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">泛型数学需运行时支持。</section>
</li>
</ul>
<h2 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: flex; flex-direction: unset; float: unset; height: auto; justify-content: center; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 20px; color: rgba(255, 255, 255, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(130, 127, 196, 1); line-height: 1.5em; letter-spacing: 0; align-items: center; border-radius: 30px; box-shadow: none; display: flex; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: center; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 10px; margin: 0; border: 1px none rgba(0, 0, 0, 1)">C# 12.0:内联数组</span></h2>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">特性表格</span></h3>
<section class="table-container" style="overflow-x: auto; padding: 0; margin: 0" data-tool="mdnice编辑器">
<table style="display: table; text-align: left">
<thead>
<tr>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">类型/构造</th>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">描述</th>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">主要用途</th>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">注意事项</th>
</tr>
</thead>
<tbody style="font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: normal; border-image: initial; border: 0">
<tr style="color: rgba(63, 63, 63, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(255, 255, 255, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">内联数组 (Inline Arrays)</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">固定大小数组结构,栈分配</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">高性能固定大小数组</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">固定大小,仅限结构体内</td>
</tr>
</tbody>
</table>
</section>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">概述</span></h3>
<p style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; text-indent: 0; padding: 16px 0 8px; margin: 0" data-tool="mdnice编辑器">内联数组通过<code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px"></code>特性定义固定大小数组结构,优化性能。</p>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">语法</span></h3>
<pre class="language-csharp highlighter-hljs"><code>
public struct StructName
{
private elementType _element0;
}</code></pre>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">示例代码</span></h3>
<pre class="language-csharp highlighter-hljs"><code>
public struct Buffer
{
private int _element0;
}
Buffer buffer = new();
buffer = 1;
buffer = 10;
Console.WriteLine(buffer); // 1</code></pre>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">适用场景</span></h3>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">高性能计算。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">替代不安全固定缓冲区。</section>
</li>
</ul>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">注意事项</span></h3>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">固定大小,运行时不可调整。</section>
</li>
</ul>
<h2 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: flex; flex-direction: unset; float: unset; height: auto; justify-content: center; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 20px; color: rgba(255, 255, 255, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(130, 127, 196, 1); line-height: 1.5em; letter-spacing: 0; align-items: center; border-radius: 30px; box-shadow: none; display: flex; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: center; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 10px; margin: 0; border: 1px none rgba(0, 0, 0, 1)">C# 13.0:参数集合扩展, 引用结构接口支持, 部分属性</span></h2>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">特性表格</span></h3>
<section class="table-container" style="overflow-x: auto; padding: 0; margin: 0" data-tool="mdnice编辑器">
<table style="display: table; text-align: left">
<thead>
<tr>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">类型/构造</th>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">描述</th>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">主要用途</th>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">注意事项</th>
</tr>
</thead>
<tbody style="font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: normal; border-image: initial; border: 0">
<tr style="color: rgba(63, 63, 63, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(255, 255, 255, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">参数集合扩展 (params Span等)</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">扩展params支持Span等</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">高性能参数传递</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">需确保Span生命周期</td>
</tr>
<tr style="color: rgba(0, 0, 0, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(248, 248, 248, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">引用结构接口支持</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">允许ref struct实现接口</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">扩展ref struct能力</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">仍受ref struct限制</td>
</tr>
<tr style="color: rgba(63, 63, 63, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(255, 255, 255, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">部分属性 (partial properties)</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">支持partial类型部分属性</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">代码生成</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">需确保定义一致</td>
</tr>
</tbody>
</table>
</section>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">概述</span></h3>
<p style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; text-indent: 0; padding: 16px 0 8px; margin: 0" data-tool="mdnice编辑器">参数集合扩展支持<code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">Span<T></code>等类型。<code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">ref struct</code>可实现接口。部分属性支持分文件定义。</p>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">语法</span></h3>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">参数集合: <code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">void Method(params Span<T> spans);</code></section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">引用结构接口: <code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">ref struct StructName : IInterface { ... }</code></section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">部分属性: <code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">public partial type Property { get; set; }</code></section>
</li>
</ul>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">示例代码</span></h3>
<pre class="language-csharp highlighter-hljs"><code>// 参数集合扩展
public void Process(params Span<int> spans)
{
foreach (var span in spans)
Console.WriteLine(string.Join(", ", span.ToArray()));
}
int[] numbers = ;
Process(numbers.AsSpan(0, 2), numbers.AsSpan(2, 1)); // 1, 2 和 3
// 引用结构接口支持
public interface IBuffer
{
void Process();
}
ref struct Buffer : IBuffer
{
public Span<int> Data;
public Buffer(Span<int> data) => Data = data;
public void Process() => Data = 10;
}
Buffer buffer = new(numbers.AsSpan());
buffer.Process();
Console.WriteLine(numbers); // 10
// 部分属性
public partial class Person
{
public partial string Name { get; set; }
}
public partial class Person
{
public partial string Name { get => _name; set => _name = value; }
private string _name;
}
var person = new Person { Name = "Alice" };
Console.WriteLine(person.Name); // Alice</code></pre>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">适用场景</span></h3>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">高性能参数传递(参数集合)。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">扩展<code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">ref struct</code>(接口支持)。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">代码生成(部分属性)。</section>
</li>
</ul>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">注意事项</span></h3>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">参数集合需管理Span生命周期。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">部分属性需确保一致性。</section>
</li>
</ul>
<h2 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: flex; flex-direction: unset; float: unset; height: auto; justify-content: center; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 20px; color: rgba(255, 255, 255, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(130, 127, 196, 1); line-height: 1.5em; letter-spacing: 0; align-items: center; border-radius: 30px; box-shadow: none; display: flex; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: center; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 10px; margin: 0; border: 1px none rgba(0, 0, 0, 1)">C# 14.0:<code>field</code> 关键字, 隐式 span 转换, <code>nameof</code> 增强, lambda 参数修饰符, partial 成员扩展, 空条件赋值</span></h2>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">特性表格</span></h3>
<section class="table-container" style="overflow-x: auto; padding: 0; margin: 0" data-tool="mdnice编辑器">
<table style="display: table; text-align: left">
<thead>
<tr>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">类型/构造</th>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">描述</th>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">主要用途</th>
<th style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: bold; background: none left top / auto no-repeat scroll padding-box border-box rgba(240, 240, 240, 1); width: auto; height: auto; border-radius: 0; min-width: 85px; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">注意事项</th>
</tr>
</thead>
<tbody style="font-size: 16px; line-height: 1.5em; letter-spacing: 0.02em; text-align: left; font-weight: normal; border-image: initial; border: 0">
<tr style="color: rgba(63, 63, 63, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(255, 255, 255, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px"><code>field</code> 关键字</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">允许在属性访问器中直接访问 backing field</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">简化属性实现</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">可能与现有字段名冲突,需使用 <code>@field</code> 或 <code>this.field</code> 区分</td>
</tr>
<tr style="color: rgba(0, 0, 0, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(248, 248, 248, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">隐式 span 转换</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">支持 <code>Span<T></code>、<code>ReadOnlySpan<T></code> 与数组间的隐式转换</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">更自然地使用 span 类型</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">需注意 span 的生命周期</td>
</tr>
<tr style="color: rgba(63, 63, 63, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(255, 255, 255, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px"><code>nameof</code> 支持未绑定泛型</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">允许 <code>nameof</code> 使用未绑定泛型类型,如 <code>nameof(List<>)</code></td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">泛型编程中的类型名称获取</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">-</td>
</tr>
<tr style="color: rgba(0, 0, 0, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(248, 248, 248, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">lambda 参数修饰符</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">允许 lambda 参数使用 <code>ref</code>、<code>out</code> 等修饰符,无需指定类型</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">增强 lambda 表达式的灵活性</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px"><code>params</code> 仍需指定类型</td>
</tr>
<tr style="color: rgba(63, 63, 63, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(255, 255, 255, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">partial 构造函数和事件</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">扩展 partial 成员到实例构造函数和事件</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">分离定义和实现,适合代码生成</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">需确保 defining 和 implementing 声明一致</td>
</tr>
<tr style="color: rgba(0, 0, 0, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(248, 248, 248, 1); width: auto; height: auto">
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">空条件赋值</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">允许在赋值左侧使用 <code>?.</code> 和 <code>?[]</code>,仅在左侧非 null 时赋值</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">简化 null 检查</td>
<td style="min-width: 85px; border-radius: 0; border: 1px solid rgba(204, 204, 204, 0.4); padding: 5px 10px">不支持 <code>++</code> 和 <code>--</code></td>
</tr>
</tbody>
</table>
</section>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">概述</span></h3>
<p style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; text-indent: 0; padding: 16px 0 8px; margin: 0" data-tool="mdnice编辑器">C# 14.0(预计2025年随.NET 10发布,截至2025年4月为预览版)引入了一系列语言特性,旨在提高开发效率和代码可读性,包括 <code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">field</code> 关键字、隐式 span 转换、<code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">nameof</code> 增强、lambda 参数修饰符、partial 成员扩展和空条件赋值。虽然未引入全新数据类型,但这些特性显著增强了现有类型的用法。</p>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0"><code>field</code> 关键字</span></h3>
<h4 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 16px; color: rgba(60, 112, 198, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 0 0 0 8px; border: 1px none rgba(0, 0, 0, 1)">概述</span></h4>
<p style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; text-indent: 0; padding: 16px 0 8px; margin: 0" data-tool="mdnice编辑器"><code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">field</code> 关键字允许在属性访问器中直接访问编译器生成的 backing field,无需显式声明。</p>
<h4 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 16px; color: rgba(60, 112, 198, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 0 0 0 8px; border: 1px none rgba(0, 0, 0, 1)">示例代码</span></h4>
<pre class="language-csharp highlighter-hljs"><code>public class Person
{
public string Name
{
get => field;
set => field = value?.Trim();
}
}
var person = new Person { Name = " Alice " };
Console.WriteLine(person.Name); // Alice</code></pre>
<h4 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 16px; color: rgba(60, 112, 198, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 0 0 0 8px; border: 1px none rgba(0, 0, 0, 1)">适用场景</span></h4>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">简化属性实现,特别是需要对 setter 进行处理时。</section>
</li>
</ul>
<h4 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 16px; color: rgba(60, 112, 198, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 0 0 0 8px; border: 1px none rgba(0, 0, 0, 1)">注意事项</span></h4>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">如果类中已有名为 <code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">field</code> 的字段,需使用 <code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">@field</code> 或 <code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">this.field</code> 区分。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">作为C# 13.0的预览特性,C# 14.0正式支持,详见field 关键字。</section>
</li>
</ul>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">隐式 span 转换</span></h3>
<h4 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 16px; color: rgba(60, 112, 198, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 0 0 0 8px; border: 1px none rgba(0, 0, 0, 1)">概述</span></h4>
<p style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; text-indent: 0; padding: 16px 0 8px; margin: 0" data-tool="mdnice编辑器">C# 14.0 为 <code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">Span<T></code> 和 <code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">ReadOnlySpan<T></code> 提供了与数组的隐式转换,使其使用更加自然。</p>
<h4 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 16px; color: rgba(60, 112, 198, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 0 0 0 8px; border: 1px none rgba(0, 0, 0, 1)">示例代码</span></h4>
<pre class="language-php highlighter-hljs"><code>Span<int> span = new int[] {1, 2, 3};
int[] array = span.ToArray();
Console.WriteLine(string.Join(", ", array)); // 1, 2, 3</code></pre>
<h4 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 16px; color: rgba(60, 112, 198, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 0 0 0 8px; border: 1px none rgba(0, 0, 0, 1)">适用场景</span></h4>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">高性能场景中,减少显式转换。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">与数组和 span 类型交互。</section>
</li>
</ul>
<h4 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 16px; color: rgba(60, 112, 198, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 0 0 0 8px; border: 1px none rgba(0, 0, 0, 1)">注意事项</span></h4>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">需确保 span 的生命周期管理,详见Span 转换。</section>
</li>
</ul>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0"><code>nameof</code> 支持未绑定泛型</span></h3>
<h4 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 16px; color: rgba(60, 112, 198, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 0 0 0 8px; border: 1px none rgba(0, 0, 0, 1)">概述</span></h4>
<p style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; text-indent: 0; padding: 16px 0 8px; margin: 0" data-tool="mdnice编辑器">允许 <code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">nameof</code> 操作符使用未绑定泛型类型。</p>
<h4 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 16px; color: rgba(60, 112, 198, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 0 0 0 8px; border: 1px none rgba(0, 0, 0, 1)">示例代码</span></h4>
<pre class="language-csharp highlighter-hljs"><code>string listName = nameof(List<>);
Console.WriteLine(listName); // List</code></pre>
<h4 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 16px; color: rgba(60, 112, 198, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 0 0 0 8px; border: 1px none rgba(0, 0, 0, 1)">适用场景</span></h4>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">泛型编程中,获取类型名称。</section>
</li>
</ul>
<h4 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 16px; color: rgba(60, 112, 198, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 0 0 0 8px; border: 1px none rgba(0, 0, 0, 1)">注意事项</span></h4>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">简单但强大的增强,适合反射场景。</section>
</li>
</ul>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">lambda 参数修饰符</span></h3>
<h4 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 16px; color: rgba(60, 112, 198, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 0 0 0 8px; border: 1px none rgba(0, 0, 0, 1)">概述</span></h4>
<p style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; text-indent: 0; padding: 16px 0 8px; margin: 0" data-tool="mdnice编辑器">允许在 lambda 表达式中为参数添加修饰符,如 <code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">ref</code>、<code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">out</code> 等,无需指定类型。</p>
<h4 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 16px; color: rgba(60, 112, 198, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 0 0 0 8px; border: 1px none rgba(0, 0, 0, 1)">示例代码</span></h4>
<pre class="language-dart highlighter-hljs"><code>var increment = (ref int x) => x++;
int num = 5;
increment(ref num);
Console.WriteLine(num); // 6</code></pre>
<h4 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 16px; color: rgba(60, 112, 198, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 0 0 0 8px; border: 1px none rgba(0, 0, 0, 1)">适用场景</span></h4>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">需要在 lambda 中修改外部变量。</section>
</li>
</ul>
<h4 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 16px; color: rgba(60, 112, 198, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 0 0 0 8px; border: 1px none rgba(0, 0, 0, 1)">注意事项</span></h4>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal"><code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">params</code> 仍需指定类型,详见lambda 表达式。</section>
</li>
</ul>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">partial 构造函数和事件</span></h3>
<h4 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 16px; color: rgba(60, 112, 198, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 0 0 0 8px; border: 1px none rgba(0, 0, 0, 1)">概述</span></h4>
<p style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; text-indent: 0; padding: 16px 0 8px; margin: 0" data-tool="mdnice编辑器">扩展 partial 成员到实例构造函数和事件,允许在 partial 类型中分离定义和实现。</p>
<h4 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 16px; color: rgba(60, 112, 198, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 0 0 0 8px; border: 1px none rgba(0, 0, 0, 1)">示例代码</span></h4>
<pre class="language-csharp highlighter-hljs"><code>// File1.cs
public partial class MyClass
{
public partial MyClass(int x);
public partial event EventHandler MyEvent;
}
// File2.cs
public partial class MyClass
{
public partial MyClass(int x) { }
public partial event EventHandler MyEvent;
}</code></pre>
<h4 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 16px; color: rgba(60, 112, 198, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 0 0 0 8px; border: 1px none rgba(0, 0, 0, 1)">适用场景</span></h4>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">代码生成场景,如 UI 设计器。</section>
</li>
</ul>
<h4 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 16px; color: rgba(60, 112, 198, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 0 0 0 8px; border: 1px none rgba(0, 0, 0, 1)">注意事项</span></h4>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">需确保 defining 和 implementing 声明一致,详见partial 成员。</section>
</li>
</ul>
<h3 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 18px; color: rgba(37, 181, 44, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; border-top: 1px none rgba(0, 0, 0, 1); border-right: 1px none rgba(0, 0, 0, 1); border-bottom: 2px solid rgba(37, 181, 44, 1); border-left: 1px none rgba(0, 0, 0, 1); padding: 2px 10px; margin: 0">空条件赋值</span></h3>
<h4 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 16px; color: rgba(60, 112, 198, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 0 0 0 8px; border: 1px none rgba(0, 0, 0, 1)">概述</span></h4>
<p style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; text-indent: 0; padding: 16px 0 8px; margin: 0" data-tool="mdnice编辑器">允许在赋值语句的左侧使用 <code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">?.</code> 和 <code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">?[]</code>,仅当左侧非 null 时执行赋值。</p>
<h4 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 16px; color: rgba(60, 112, 198, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 0 0 0 8px; border: 1px none rgba(0, 0, 0, 1)">示例代码</span></h4>
<pre class="language-csharp highlighter-hljs"><code>string? text = null;
text?.Length = 5; // 不执行赋值
List<int>? list = null;
list? = 10; // 不执行赋值
list = new List<int> { 0 };
list? = 10; // 执行赋值,list = 10
Console.WriteLine(list); // 10</code></pre>
<h4 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 16px; color: rgba(60, 112, 198, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 0 0 0 8px; border: 1px none rgba(0, 0, 0, 1)">适用场景</span></h4>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">简化 null 检查,避免 NullReferenceException。</section>
</li>
</ul>
<h4 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: block; flex-direction: unset; float: unset; height: auto; justify-content: unset; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 16px; color: rgba(60, 112, 198, 1); line-height: 1.5em; letter-spacing: 0; align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: inline-block; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: unset; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 0 0 0 8px; border: 1px none rgba(0, 0, 0, 1)">注意事项</span></h4>
<ul style="list-style-type: disc; color: rgba(0, 0, 0, 1); padding: 0 0 0 25px; margin: 8px 0" data-tool="mdnice编辑器">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; font-weight: normal">不支持 <code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">++</code> 和 <code style="background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">--</code> 操作,详见空条件赋值。</section>
</li>
</ul>
<h2 style="align-items: unset; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); border-radius: 0; box-shadow: none; display: flex; flex-direction: unset; float: unset; height: auto; justify-content: center; line-height: 1.5em; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 0; margin: 30px 0 15px; border: 1px none rgba(0, 0, 0, 1)" data-tool="mdnice编辑器"><span class="content" style="font-size: 20px; color: rgba(255, 255, 255, 1); background: none left top / auto no-repeat scroll padding-box border-box rgba(130, 127, 196, 1); line-height: 1.5em; letter-spacing: 0; align-items: center; border-radius: 30px; box-shadow: none; display: flex; font-weight: bold; flex-direction: unset; float: unset; height: auto; justify-content: center; overflow-x: unset; overflow-y: unset; position: relative; text-align: left; text-indent: 0; text-shadow: none; transform: none; width: auto; -webkit-box-reflect: unset; padding: 10px; margin: 0; border: 1px none rgba(0, 0, 0, 1)">结语</span></h2>
<p style="color: rgba(63, 63, 63, 1); font-size: 16px; line-height: 1.8em; letter-spacing: 0.02em; text-align: left; text-indent: 0; padding: 16px 0 8px; margin: 0" data-tool="mdnice编辑器">C# 7.0至C# 14.0的类型系统新增内容涵盖了值元组、Span、ReadOnlySpan、Memory、ReadOnlyMemory、可空引用类型、记录、本机大小整数、记录结构、内联数组等数据类型,以及只读结构、引用结构、必需成员、泛型数学支持等增强。C# 14.0通过<code style="color: rgba(40, 202, 113, 1); font-size: 14px; line-height: 1.8em; letter-spacing: 0; background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05); width: auto; height: auto; border-radius: 4px; overflow-wrap: break-word; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; word-break: break-all; border-top: 3px none rgba(0, 0, 0, 1); border-right: 3px none rgba(0, 0, 0, 0.4); border-bottom: 3px none rgba(0, 0, 0, 0.4); border-left: 3px none rgba(0, 0, 0, 0.4); padding: 2px 4px; margin: 0 2px">field</code>关键字、隐式 span 转换等特性进一步优化了现有类型的用法。这些特性满足了从高性能内存管理到类型安全建模的多种需求。资深C#工程师可根据场景选择类型,如使用Span优化性能,记录建模数据。由于C# 14.0尚在预览阶段,建议关注dotnet/roslyn以获取最新更新。</p>
</section>
</div>
<div id="MySignature" role="contentinfo">
<p>
本文来自博客园,作者:AI·NET极客圈,转载请注明原文链接:https://www.cnblogs.com/code-daily/p/18844112
</p>
<img src="https://images.cnblogs.com/cnblogs_com/blogs/272929/galleries/2447197/o_250311050355_AI.NET%20Logo.png" width="61.8%" style="margin-left:20px"/>
<p>
欢迎关注我们的公众号,作为.NET工程师,我们聚焦人工智能技术,探讨 AI 的前沿应用与发展趋势,为你立体呈现人工智能的无限可能,让我们共同携手共同进步。
</p><br><br>
来源:https://www.cnblogs.com/code-daily/p/18844112
頁:
[1]