Get a read-only wrapper for the specified array in CSharp
Description
The following code shows how to get a read-only wrapper for the specified array.
Example
// w w w. j a v a2s. c o m
using System;
using System.Collections.Generic;
public class MainClass {
public static void Main() {
String[] myArr = { "The", "quick", "brown", "fox" };
IList<String> myList = Array.AsReadOnly( myArr );
try {
myList[3] = "CAT";
}
catch ( NotSupportedException e ) {
Console.WriteLine( "{0} - {1}", e.GetType(), e.Message );
Console.WriteLine();
}
}
}
The code above generates the following result.