MSDN Docs / System.Collections / IReadOnlyList

IReadOnlyList<T> Interface

The IReadOnlyList<T> interface provides a readโ€‘only, indexable collection of elements.

Namespace: System.Collections

Assembly: System.Runtime.dll

Definition

public interface IReadOnlyList<T> : IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable

Members

MemberSignatureDescription
Property T this[int index] { get; } Gets the element at the specified index.
Property int Count { get; } Gets the number of elements in the collection.
Method IEnumerator<T> GetEnumerator(); Returns an enumerator that iterates through the collection.

Example

using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        IReadOnlyList<string> days = new List<string>
        {
            "Sunday", "Monday", "Tuesday",
            "Wednesday", "Thursday", "Friday", "Saturday"
        };

        Console.WriteLine($"First day: {days[0]}");
        Console.WriteLine($"Total days: {days.Count}");
    }
}

See Also