Baza wiedzyCentrum egzaminacyjne
PLPolski
Wybierz język13

CKTIS / C#

System.ReadOnlyMemory: odniesienie praktyczne

System.ReadOnlyMemory: odniesienie praktyczne: ReadOnlyMemory<T> udostępnia trwały, tylko-do-odczytu widok bufora możliwy do użycia w async.

Wersja: .NET API; verified against .NET 10 reference surface

Składnia

System.ReadOnlyMemory /* select a documented member or constructor */

ReadOnlyMemory udostępnia trwały, tylko-do-odczytu widok bufora możliwy do użycia w async.

Stosuj jako parametr, gdy odbiorca nie powinien modyfikować elementów.

ReadOnly dotyczy widoku; właściciel nadal może zmienić bazowy bufor.

Slice kontroluje zakres, a pamięć po zwolnieniu właściciela jest nieważna.

Kompletny program rzeczywiście używa System.ReadOnlyMemory; oczekiwany stdout to dokładnie bc.

Przykłady

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;

ReadOnlyMemory<char> memory = "abcd".AsMemory(1, 2);
Console.WriteLine(memory.ToString());

Wynik

bc

Kompletny program rzeczywiście używa `System.ReadOnlyMemory`; oczekiwany stdout to dokładnie `bc`.

Źródła