CKTIS / C#
System.IO.MemoryStream: odniesienie praktyczne
System.IO.MemoryStream: odniesienie praktyczne: MemoryStream jest strumieniem bajtów w pamięci z Position, Length i Capacity.
Wersja: .NET API; verified on .NET 10.0.14
Składnia
System.IO.MemoryStream /* select a documented member or constructor */MemoryStream jest strumieniem bajtów w pamięci z Position, Length i Capacity.
Stosuj do małych/średnich buforów wymagających API Stream bez I/O plikowego.
ToArray kopiuje, GetBuffer może ujawnić nadmiarową pojemność, a Dispose nie zeruje danych.
Samo Seek poza Length zmienia Position, lecz nie rozszerza strumienia ani nie tworzy bajtów; luka zostaje wyzerowana dopiero przez późniejszy zapis rozszerzający strumień lub SetLength. Konstruktor nad tablicą może być nierozszerzalny.
Kompletny program rzeczywiście używa System.IO.MemoryStream; oczekiwany stdout to dokładnie 65.
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;
using var stream = new MemoryStream();
stream.WriteByte(65);
Console.WriteLine(stream.ToArray()[0]);
Wynik
65
Kompletny program rzeczywiście używa `System.IO.MemoryStream`; oczekiwany stdout to dokładnie `65`.