C# List AsReadOnly
Description
List
returns a read-only IList
Syntax
List.AsReadOnly
has the following syntax.
public ReadOnlyCollection<T> AsReadOnly()
Example
using System;/*from ww w. ja v a 2 s . c o m*/
using System.Collections.Generic;
public class Example
{
public static void Main()
{
List<string> myData = new List<string>(4);
Console.WriteLine("\nCapacity: {0}", myData.Capacity);
myData.Add("A");
myData.Add("B");
myData.Add("C");
myData.Add("D");
IList<string> romyData = myData.AsReadOnly();
}
}
The code above generates the following result.