CSharpTest.Net
Add(T) Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Collections Namespace > BTreeList<T> Class : Add(T) Method

value
The object to use as the value of the element to add.

Glossary Item Box

Adds an element with the provided value to the IList.

Syntax

Visual Basic (Declaration) 
Public Sub Add( _
   ByVal value As T _
) 
C# 
public void Add( 
   T value
)

Parameters

value
The object to use as the value of the element to add.

Exceptions

ExceptionDescription
System.ArgumentExceptionAn element with the same value already exists in the IList.
System.NotSupportedExceptionThe IList is read-only.

Example

Library/Library.Test/TestBTreeList.cs

C#Copy Code
BTreeList<int> test = new BTreeList<int>(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
IList<int> list = test;
for (int i = 10; i < 1000; i++)
    test.Add(i);

for(int i=900; i >0; i-=100)
{
    Assert.IsTrue(test.Contains(i));
    Assert.AreEqual(i, list.IndexOf(i));
    list.RemoveAt(i);
    Assert.IsFalse(test.Contains(i));
    Assert.AreEqual(-1, list.IndexOf(i));
    Assert.AreEqual(i + 1, list[i]);
}

list.RemoveAt(0);
list.RemoveAt(1);
list.RemoveAt(2);
Assert.AreEqual(1, list[0]);
Assert.AreEqual(3, list[1]);
Assert.AreEqual(5, list[2]);

Assert.AreEqual(1000 - 12, list.Count);
VB.NETCopy Code
Dim test As New BTreeList(Of Integer)(New Integer() {0, 1, 2, 3, 4, 5, _
    6, 7, 8, 9})
Dim list As IList(Of Integer) = test
Dim i As Integer = 10
While i < 1000
    test.Add(i)
    System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While

Dim i As Integer = 900
While i > 0
    Assert.IsTrue(test.Contains(i))
    Assert.AreEqual(i, list.IndexOf(i))
    list.RemoveAt(i)
    Assert.IsFalse(test.Contains(i))
    Assert.AreEqual(-1, list.IndexOf(i))
    Assert.AreEqual(i + 1, list(i))
    i -= 100
End While

list.RemoveAt(0)
list.RemoveAt(1)
list.RemoveAt(2)
Assert.AreEqual(1, list(0))
Assert.AreEqual(3, list(1))
Assert.AreEqual(5, list(2))

Assert.AreEqual(1000 - 12, list.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