using System.Collections.Generic;
public static void Main()
String[] myArr = { "The", "quick", "brown", "fox" };
Console.WriteLine("The string array initially contains the following values:");
PrintIndexAndValues(myArr);
IList<String> myList = myArr.AsReadOnly();
Console.WriteLine("The read-only IList contains the following values:");
PrintIndexAndValues(myList);
catch (NotSupportedException e)
Console.WriteLine("{0} - {1}", e.GetType(), e.Message);
Console.WriteLine("After changing the third element, the string array contains the following values:");
PrintIndexAndValues(myArr);
Console.WriteLine("After changing the third element, the read-only IList contains the following values:");
PrintIndexAndValues(myList);
public static void PrintIndexAndValues(String[] myArr)
for (int i = 0; i < myArr.Length; i++)
Console.WriteLine(" [{0}] : {1}", i, myArr[i]);
public static void PrintIndexAndValues(IList<String> myList)
for (int i = 0; i < myList.Count; i++)
Console.WriteLine(" [{0}] : {1}", i, myList[i]);