CKTIS / C#
System.Collections.Generic.IReadOnlyList: referencia práctica
System.Collections.Generic.IReadOnlyList: referencia práctica: IReadOnlyList<T> expone Count y lectura indexada sin métodos de mutación en la interfaz.
Versión: .NET API; verified on .NET 10.0.14
Sintaxis
System.Collections.Generic.IReadOnlyList /* select a documented member or constructor */IReadOnlyList expone Count y lectura indexada sin métodos de mutación en la interfaz.
Úsalo cuando los consumidores necesiten acceso aleatorio pero no deban recibir operaciones de escritura de la lista.
La interfaz no congela el objeto subyacente ni los objetos referencia mutables almacenados como elementos.
El índice debe estar entre cero y Count menos uno; la implementación, no IReadOnlyList, define la excepción concreta para un índice fuera del intervalo.
El programa completo usa realmente System.Collections.Generic.IReadOnlyList; su stdout esperado exacto es b.
Ejemplos
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]);
Resultado
b
El programa completo usa realmente `System.Collections.Generic.IReadOnlyList`; su stdout esperado exacto es `b`.