CSharpTest.Net
AddOrUpdate(TKey,TValue,KeyValueUpdate<TKey,TValue>) Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Collections Namespace > SynchronizedDictionary<TKey,TValue> Class > AddOrUpdate Method : AddOrUpdate(TKey,TValue,KeyValueUpdate<TKey,TValue>) Method

key
addValue
fnUpdate

Glossary Item Box

Adds a key/value pair to the IDictionary if the key does not already exist, or updates a key/value pair if the key already exists.

Syntax

Visual Basic (Declaration) 
Public Overloads Function AddOrUpdate( _
   ByVal key As TKey, _
   ByVal addValue As TValue, _
   ByVal fnUpdate As CSharpTest.Net.Collections.KeyValueUpdate(Of TKey,TValue) _
) As TValue
C# 
public TValue AddOrUpdate( 
   TKey key,
   TValue addValue,
   CSharpTest.Net.Collections.KeyValueUpdate<TKey,TValue> fnUpdate
)

Parameters

key
addValue
fnUpdate

Example

Library/Library.Test/TestSynchronizedCollections.cs

C#Copy Code
SynchronizedDictionary<int, string> data =
    new SynchronizedDictionary<int, string>(new Dictionary<int, string>());
Assert.AreEqual("a", data.AddOrUpdate(1, "a", (k, v) => k.ToString()));
Assert.AreEqual("1", data.AddOrUpdate(1, "a", (k, v) => k.ToString()));

Assert.AreEqual("b", data.AddOrUpdate(2, k => "b", (k, v) => k.ToString()));
Assert.AreEqual("2", data.AddOrUpdate(2, k => "b", (k, v) => k.ToString()));
VB.NETCopy Code
Dim data As New SynchronizedDictionary(Of Integer, String)(New Dictionary(Of Integer, String)())
Assert.AreEqual("a", data.AddOrUpdate(1, "a", Function(k, v) k.ToString()))
Assert.AreEqual("1", data.AddOrUpdate(1, "a", Function(k, v) k.ToString()))

Assert.AreEqual("b", data.AddOrUpdate(2, Function(k) "b", Function(k, v) k.ToString()))
Assert.AreEqual("2", data.AddOrUpdate(2, Function(k) "b", Function(k, v) k.ToString()))

Requirements

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

See Also

Generated with Document! X 2011 by Innovasys