Adds an element with the provided key and value to the
IDictionary.
Syntax
Visual Basic (Declaration) | |
---|
Public Sub Add( _
ByVal key As TKey, _
ByVal value As TValue _
) |
Parameters
- key
- value
Exceptions
Exception | Description |
System.ArgumentOutOfRangeException | The exception that is thrown when the value of an argument is outside the allowable range of values as defined by the invoked method. |
Example
Library/Library.Test/TestLurchTable.cs
C# | Copy Code |
---|
LurchTableTest<int, string> test = new LurchTableTest<int, string>();
for (int i = 0; i < 10; i++)
test.Add(i, i.ToString());
for (int i = 0; i < 10; i++)
Assert.IsTrue(test.ContainsKey(i));
string cmp;
for (int i = 0; i < 10; i++)
Assert.IsTrue(test.TryGetValue(i, out cmp) && cmp == i.ToString());
for (int i = 0; i < 10; i++)
Assert.IsTrue(test.Remove(i)); |
VB.NET | Copy Code |
---|
Dim test As New LurchTableTest(Of Integer, String)()
Dim i As Integer = 0
While i < 10
test.Add(i, i.ToString())
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While
Dim i As Integer = 0
While i < 10
Assert.IsTrue(test.ContainsKey(i))
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While
Dim cmp As String
Dim i As Integer = 0
While i < 10
Assert.IsTrue(test.TryGetValue(i, cmp) AndAlso cmp = i.ToString())
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While
Dim i As Integer = 0
While i < 10
Assert.IsTrue(test.Remove(i))
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While |
Requirements
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
See Also