CSharpTest.Net
ReadOnlyList<T> Constructor(IEnumerable<T>)
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Collections Namespace > ReadOnlyList<T> Class > ReadOnlyList<T> Constructor : ReadOnlyList<T> Constructor(IEnumerable<T>)

collection

Glossary Item Box

Creates a readonly list of T by copying the enumeration into a List<T>

Syntax

Visual Basic (Declaration) 
Public Function New( _
   ByVal collection As IEnumerable(Of T) _
)
C# 
public ReadOnlyList<T>( 
   IEnumerable<T> collection
)

Parameters

collection

Example

Library/Library.Test/TestReadOnlyList.cs

C#Copy Code
ICollection read = new ReadOnlyList<int>((IEnumerable<int>)new int[] { 5, 10, 15 });
Assert.AreEqual(3, read.Count);
Assert.IsFalse(read.IsSynchronized);
Assert.IsTrue(Object.ReferenceEquals(read, read.SyncRoot));

long[] lary = new long[3];
read.CopyTo(lary, 0);
Assert.AreEqual(5L, lary[0]);
Assert.AreEqual(10L, lary[1]);
Assert.AreEqual(15L, lary[2]);

ICollection copy = (ICollection)((ICloneable)read).Clone();
Assert.AreEqual(3, copy.Count);
VB.NETCopy Code
Dim read As ICollection = New ReadOnlyList(Of Integer)(DirectCast(New Integer() {5, 10, 15}, IEnumerable(Of Integer)))
Assert.AreEqual(3, read.Count)
Assert.IsFalse(read.IsSynchronized)
Assert.IsTrue([Object].ReferenceEquals(read, read.SyncRoot))

Dim lary As Long() = New Long(3) {}
read.CopyTo(lary, 0)
Assert.AreEqual(5L, lary(0))
Assert.AreEqual(10L, lary(1))
Assert.AreEqual(15L, lary(2))

Dim copy As ICollection = DirectCast((DirectCast(read, ICloneable)).Clone(), ICollection)
Assert.AreEqual(3, copy.Count)

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys