Baza wiedzyCentrum egzaminacyjne
PLPolski
Wybierz język13

CKTIS / C#

System.Collections.Immutable.ImmutableList: odniesienie praktyczne

System.Collections.Immutable.ImmutableList: odniesienie praktyczne: ImmutableList<T> zwraca strukturalnie współdzielone wersje po zmianie.

Wersja: .NET API; verified on .NET 10.0.14

Składnia

System.Collections.Immutable.ImmutableList /* select a documented member or constructor */

ImmutableList zwraca strukturalnie współdzielone wersje po zmianie.

Stosuj, gdy potrzebujesz listowych operacji i trwałych poprzednich wersji.

Jej koszty indeksowania i aktualizacji różnią się od List; nie jest automatycznie szybsza.

Indeks poza zakresem zgłasza wyjątek; elementy obiektowe pozostają mutowalne.

Kompletny program rzeczywiście używa System.Collections.Immutable.ImmutableList; oczekiwany stdout to dokładnie 2.

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;

var list = ImmutableList<int>.Empty.Add(1).Add(2);
Console.WriteLine(list[1]);

Wynik

2

Kompletny program rzeczywiście używa `System.Collections.Immutable.ImmutableList`; oczekiwany stdout to dokładnie `2`.

Źródła