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.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var