Baza znanjaIzpitno središče
SLSlovenščina
Izberi jezik13

CKTIS / C#

System.Buffers.IBufferWriter: praktična referenca

System.Buffers.IBufferWriter: praktična referenca: IBufferWriter<T> prek GetSpan ali GetMemory ponudi zapisljiv prostor, Advance pa potrdi natančno število zapisanih elementov.

Različica: .NET API; verified on .NET 10.0.14

Sintaksa

System.Buffers.IBufferWriter /* select a documented member or constructor */

IBufferWriter prek GetSpan ali GetMemory ponudi zapisljiv prostor, Advance pa potrdi natančno število zapisanih elementov.

Uporabite ga v serializatorjih in cevovodih, ki podatke ustvarjajo postopoma brez znane končne velikosti.

Po naslednji zahtevi ne hranite span ali memory in z Advance ne potrdite več elementov, kot jih je bilo ponujenih.

SizeHint nič je veljaven, izvedba pa lahko vrne večji prostor od zahtevanega minimuma.

Celoten program dejansko uporabi System.Buffers.IBufferWriter; natančno pričakovani stdout je 9.

Primeri

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;

IBufferWriter<int> writer = new ArrayBufferWriter<int>();
var span = writer.GetSpan(1);
span[0] = 9;
writer.Advance(1);
Console.WriteLine(((ArrayBufferWriter<int>)writer).WrittenSpan[0]);

Rezultat

9

Celoten program dejansko uporabi `System.Buffers.IBufferWriter`; natančno pričakovani stdout je `9`.

Viri