CSharpTest.Net
AddRange Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Collections Namespace > OrdinalList Class : AddRange Method

contents

Glossary Item Box

Adds a range of integer ordinals into the collection

Syntax

Visual Basic (Declaration) 
Public Sub AddRange( _
   ByVal contents As IEnumerable(Of Integer) _
) 
C# 
public void AddRange( 
   IEnumerable<int> contents
)

Parameters

contents

Example

Library/Library.Test/TestOrdinalList.cs

C#Copy Code
OrdinalList list = new OrdinalList();
list.AddRange(new int[] { 5, 10, 20 });

ICollection coll = list;
Assert.IsFalse(coll.IsSynchronized);
Assert.IsTrue(Object.ReferenceEquals(coll, coll.SyncRoot));
            
int[] copy = new int[3];
coll.CopyTo(copy, 0);
Assert.AreEqual(5, copy[0]);
Assert.AreEqual(10, copy[1]);
Assert.AreEqual(20, copy[2]);

byte[] bits = new byte[3];
coll.CopyTo(bits, 0);
Assert.AreEqual(32, bits[0]);
Assert.AreEqual(4, bits[1]);
Assert.AreEqual(16, bits[2]);

List<int> tmp = new List<int>();
foreach (int i in coll)
    tmp.Add(i);
Assert.AreEqual(3, tmp.Count);
Assert.AreEqual(5, tmp[0]);
Assert.AreEqual(10, tmp[1]);
Assert.AreEqual(20, tmp[2]);
VB.NETCopy Code
Dim list As New OrdinalList()
list.AddRange(New Integer() {5, 10, 20})

Dim coll As ICollection = list
Assert.IsFalse(coll.IsSynchronized)
Assert.IsTrue([Object].ReferenceEquals(coll, coll.SyncRoot))

Dim copy As Integer() = New Integer(3) {}
coll.CopyTo(copy, 0)
Assert.AreEqual(5, copy(0))
Assert.AreEqual(10, copy(1))
Assert.AreEqual(20, copy(2))

Dim bits As Byte() = New Byte(3) {}
coll.CopyTo(bits, 0)
Assert.AreEqual(32, bits(0))
Assert.AreEqual(4, bits(1))
Assert.AreEqual(16, bits(2))

Dim tmp As New List(Of Integer)()
For Each i As Integer In coll
    tmp.Add(i)
Next
Assert.AreEqual(3, tmp.Count)
Assert.AreEqual(5, tmp(0))
Assert.AreEqual(10, tmp(1))
Assert.AreEqual(20, tmp(2))

Requirements

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

See Also

Generated with Document! X 2011 by Innovasys