Znalostní bázeCentrum zkoušek
CSČeština
Vybrat jazyk13

CKTIS / C#

System.Collections.Generic.IReadOnlyList: praktická reference

System.Collections.Generic.IReadOnlyList: praktická reference: IReadOnlyList<T> zpřístupňuje Count a indexované čtení bez mutačních metod na rozhraní.

Verze: .NET API; verified on .NET 10.0.14

Syntaxe

System.Collections.Generic.IReadOnlyList /* select a documented member or constructor */

IReadOnlyList zpřístupňuje Count a indexované čtení bez mutačních metod na rozhraní.

Použijte jej, když spotřebitel potřebuje náhodný přístup, ale nemá dostat operace zápisu do seznamu.

Rozhraní nezmrazí podkladový objekt ani měnitelné referenční objekty uložené jako prvky.

Index musí být v rozsahu nula až Count minus jedna; konkrétní výjimku pro index mimo rozsah určuje implementace, nikoli IReadOnlyList.

Úplný program skutečně používá System.Collections.Generic.IReadOnlyList; přesně očekávaný stdout je b.

Příklady

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;

IReadOnlyList<string> values = new[] { "a", "b" };
Console.WriteLine(values[1]);

Výsledek

b

Úplný program skutečně používá `System.Collections.Generic.IReadOnlyList`; přesně očekávaný stdout je `b`.

Zdroje