CSharpTest.Net
ReadOnlyList<T> Constructor(IList<T>,Boolean)
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(IList<T>,Boolean)

list
clone

Glossary Item Box

Creates a readonly list of T creating a copy if desired

Syntax

Visual Basic (Declaration) 
Public Function New( _
   ByVal list As IList(Of T), _
   ByVal clone As Boolean _
)
C# 
public ReadOnlyList<T>( 
   IList<T> list,
   bool clone
)

Parameters

list
clone

Example

Library/Library.Test/TestReadOnlyList.cs

C#Copy Code
List<string> strings = new List<string>(new string[] { "a", "b", "c" });
ReadOnlyList<String> read = new ReadOnlyList<string>(strings, false);

Assert.AreEqual(3, read.Count);
strings.RemoveAt(2);
Assert.AreEqual(2, read.Count);
Assert.AreEqual("a", read[0]);
Assert.AreEqual("b", read[1]);

Assert.AreEqual("a,b", String.Join(",", read.Clone().ToArray()));
VB.NETCopy Code
Dim strings As New List(Of String)(New String() {"a", "b", "c"})
Dim read As ReadOnlyList(Of [String]) = New ReadOnlyList(Of String)(strings, False)

Assert.AreEqual(3, read.Count)
strings.RemoveAt(2)
Assert.AreEqual(2, read.Count)
Assert.AreEqual("a", read(0))
Assert.AreEqual("b", read(1))

Assert.AreEqual("a,b", [String].Join(",", read.Clone().ToArray()))

Requirements

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

See Also

Generated with Document! X 2011 by Innovasys