Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

System.Collections.Immutable.ImmutableArray: practical reference

System.Collections.Immutable.ImmutableArray: practical reference: ImmutableArray<T> is a value-type immutable array whose update operations return another structure.

Version: .NET API; verified on .NET 10.0.14

Syntax

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

ImmutableArray is a value-type immutable array whose update operations return another structure.

Use it for stable snapshots with fast indexing and inexpensive transfer of the array value.

The copy is shallow, and default(ImmutableArray) is an uninitialized state distinct from Empty.

Some operations throw on the default state, and Add returns a new array without changing the original.

The complete program actually uses System.Collections.Immutable.ImmutableArray; its exact expected stdout is 3.

Examples

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 values = ImmutableArray.Create(1, 2).Add(3);
Console.WriteLine(values.Length);

Result

3

The complete program actually uses `System.Collections.Immutable.ImmutableArray`; its exact expected stdout is `3`.

Sources