Baza wiedzyCentrum egzaminacyjne
PLPolski
Wybierz język13

CKTIS / C#

System.Collections.Generic.IReadOnlyList: odniesienie praktyczne

System.Collections.Generic.IReadOnlyList: odniesienie praktyczne: IReadOnlyList<T> udostępnia Count i indeksowany odczyt bez metod mutacji.

Wersja: .NET API; verified on .NET 10.0.14

Składnia

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

IReadOnlyList udostępnia Count i indeksowany odczyt bez metod mutacji.

Stosuj do losowego odczytu listy bez przekazywania metod zapisu.

Interfejs nie zamraża obiektu bazowego ani elementów referencyjnych.

Indeks musi mieścić się w zakresie 0..Count-1; konkretny wyjątek dla indeksu poza zakresem określa implementacja, a nie interfejs IReadOnlyList.

Kompletny program rzeczywiście używa System.Collections.Generic.IReadOnlyList; oczekiwany stdout to dokładnie b.

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;

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

Wynik

b

Kompletny program rzeczywiście używa `System.Collections.Generic.IReadOnlyList`; oczekiwany stdout to dokładnie `b`.

Źródła