Array.AsReadOnly : Array « System « C# / C Sharp by API






Array.AsReadOnly

  

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;


public class Starter {
    public static void Main() {
        int[] zArray = { 1, 2, 3, 4 };
        zArray[1] = 10;

        ReadOnlyCollection<int> roArray = Array.AsReadOnly(zArray);
        foreach (int number in roArray) {
            Console.WriteLine(number);
        }
        roArray[1] = 2; // compile error
    }
}

   
    
  








Related examples in the same category

1.Array.BinarySearch
2.Array.Clone
3.Array.ConvertAll
4.Array.Copy
5.Array.CopyTo
6.Array.Count
7.Array.CreateInstance
8.Array.Exists
9.Array.Find
10.Array.FindAll
11.Array.ForEach
12.Array.GetEnumerator()
13.Array.GetLength()
14.Array.GetLowerbound
15.Array.GetUpperBound
16.Array.IndexOf
17.Array.LastIndexOf
18.Array.Length
19.Array.Rank
20.Array.Resize
21.Array.Reverse
22.Array.Reverse(nums, 1, 3)
23.Array.Sort
24.Array.Sort(names, Comparer.DefaultInvariant)
25.Array.SyncRoot