CKTIS / C#
System.Span: praktická referencia
System.Span: praktická referencia: Span<T> je zásobníkový meniteľný pohľad na súvislú oblasť pamäte.
Verzia: .NET API; verified against .NET 10 reference surface
Syntax
System.Span /* select a documented member or constructor */Span je zásobníkový meniteľný pohľad na súvislú oblasť pamäte.
Použite na synchrónnych kritických cestách na prácu bez kopírovania.
Ako ref struct nemôže uniknúť na haldu ani prekročiť await alebo yield.
Slice a indexovanie kontrolujú hranice; stackalloc má obmedzený rozpočet zásobníka.
Úplný program skutočne používa System.Span; presne očakávaný stdout je 3,2,1.
Príklady
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;
Span<int> span = stackalloc[] { 1, 2, 3 };
span.Reverse();
Console.WriteLine(string.Join(",", span.ToArray()));
Výsledok
3,2,1
Úplný program skutočne používa `System.Span`; presne očakávaný stdout je `3,2,1`.