C# List AsReadOnly() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
List

Definition

In C#, List.AsReadOnly() hands you a ReadOnlyCollection<T>: a wrapper that lets code read the items and the Count but offers no Add, Remove, or Clear. The type lives in System.Collections.ObjectModel.

The wrapper is a live view, not a copy. If the owner of the original list adds an item later, the read-only wrapper shows it at once. This makes it a good way to let other code look at your list without letting it change the list. For a true frozen snapshot, use ToArray() instead.

This is an instance member of List<T> (System.Collections.Generic). Call it on a list variable, such as numbers.AsReadOnly(...). A List<T> is a class, so two variables can share one list. It keeps items in the order you put them, allows duplicates, and grows when needed. An array, by comparison, has a fixed length.

Syntax

Add using System.Collections.ObjectModel; and store the result in a ReadOnlyCollection<T>.

C#
using System.Collections.ObjectModel;

List<int> numbers = new List<int> { 1, 2, 3 };
ReadOnlyCollection<int> view = numbers.AsReadOnly();
int first = view[0];     // reading is fine
// view.Add(4);          // compile error: no Add method
CallWhat it does
numbers.AsReadOnly()A read-only wrapper around the same list. No copy is made.
view[0]Reading by index works like a list.
view.CountThe size of the underlying list, always up to date.

AsReadOnly is O(1) because it only wraps the list. The wrapper itself cannot be changed, but the original list can, and the wrapper shows those changes. It is a wrapper, not a deep protection: for classes, the items are the same objects, so someone can still change an object's fields through the wrapper. Casting the wrapper to IList<T> and calling Add throws NotSupportedException.

Library declarations
C#
public ReadOnlyCollection<T> AsReadOnly();

Parameters

ParameterDescription
NoneAsReadOnly() takes no parameters.

Return Value

Return ValueDescription
ReadOnlyCollectionA read-only wrapper around the list. It has Count, an indexer, Contains, IndexOf, and enumeration, but no methods that change the list.

C# Examples

Example 1 — Read Items Through a Read-Only View

Wrap a list and read it. The wrapper has no Add method at all.

C#
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

class Program {
    static void Main() {
        List<int> numbers = new List<int> { 10, 20, 30 };

        ReadOnlyCollection<int> view = numbers.AsReadOnly();

        Console.WriteLine(view.Count);
        Console.WriteLine(view[1]);
        Console.WriteLine(view.Contains(30));
        Console.WriteLine(((IList<int>)view).IsReadOnly);
    }
}

How It Works

  1. Wrapper type. ReadOnlyCollection<int> comes from System.Collections.ObjectModel. That is why that using line is needed.
  2. Reading works. Count, the indexer view[1], and Contains all behave as they do on a list.
  3. Writing is missing. Typing view.Add(4) would not compile, because the wrapper has no Add method.
  4. Ask the interface. Through the IList<int> interface, IsReadOnly is True, which confirms the wrapper cannot be edited.

Example 2 — The View Follows the List

Change the original list after wrapping it. The read-only view shows the change at once, because it is not a copy.

C#
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

class Program {
    static void Main() {
        List<string> names = new List<string> { "Asha", "Ben" };
        ReadOnlyCollection<string> view = names.AsReadOnly();

        Console.WriteLine(view.Count);

        names.Add("Chen");
        names[0] = "Zara";

        Console.WriteLine(view.Count);
        Console.WriteLine(string.Join(", ", view));
    }
}

How It Works

  1. Wrap once. view is created when the list has two names, and it never needs to be created again.
  2. Owner still edits. The code that holds names can still call Add and use the indexer. The wrapper only limits the code that holds view.
  3. Live update. The view now reports 3 items, because it reads from the same list underneath.
  4. Replace also shows. The first item was changed to "Zara" through the list, and the view prints it. This is why it is a live view and not a snapshot.

Example 3 — Expose a List Without Letting It Change

A class keeps its list private and returns a read-only wrapper. Outside code cannot change the list, even by casting.

C#
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

class Team {
    private List<string> members = new List<string>();

    public ReadOnlyCollection<string> Members {
        get { return members.AsReadOnly(); }
    }

    public void Join(string name) { members.Add(name); }
}

class Program {
    static void Main() {
        Team team = new Team();
        team.Join("Asha");
        team.Join("Ben");

        Console.WriteLine(team.Members.Count);

        try {
            ((IList<string>)team.Members).Add("Hacker");
        } catch (NotSupportedException) {
            Console.WriteLine("read-only");
        }

        Console.WriteLine(team.Members.Count);
    }
}

How It Works

  1. Private list. members is private, so outside code cannot touch it. Only the Join method adds to it.
  2. Safe property. The Members property returns a read-only wrapper, so callers can read the names but have no Add to call.
  3. Casting does not help. Forcing the wrapper to IList<string> and calling Add throws NotSupportedException, which the catch block reports.
  4. Unchanged. The member count is still 2. The class controls every change through its own methods.

Frequently Asked Questions

It returns a ReadOnlyCollection<T> that wraps the list. Code can read items but cannot add, remove, or replace them through the wrapper.
No. It is a live view of the same list. If the original list changes later, the read-only wrapper shows the change.
System.Collections.ObjectModel. Add using System.Collections.ObjectModel; to your file.
Not the list structure: Add and Remove throw NotSupportedException even via IList<T>. But for classes, the objects are shared, so their fields can still be changed.
Copy the items with ToArray() or new List<T>(list). Those copies do not change when the original list changes.

Next: BinarySearch()

Fast search in a sorted List; returns the index, or a negative number when missing.

BinarySearch() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful