Aracılığıyla paylaş


IsolatedStorageSettings.Add Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Adds an entry to the dictionary for the key-value pair.

Namespace:  System.IO.IsolatedStorage
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Sub Add ( _
    key As String, _
    value As Object _
)
public void Add(
    string key,
    Object value
)

Parameters

Implements

IDictionary<TKey, TValue>.Add(TKey, TValue)

Exceptions

Exception Condition
ArgumentNullException

key is nulla null reference (Nothing in Visual Basic).

ArgumentException

key already exists in the dictionary.

Remarks

Use this method to add key-value pairs to isolated storage.

Examples

The following example tries to add a key-value pair for the user's name to the settings dictionary. If the data is added successfully, a confirmation is displayed in a TextBox named tbResults. If the key already exists, an exception message is displayed. This example is part of a larger example for the IsolatedStorageSettings class.

Try
    userSettings.Add("name", tbName.Text)
    tbResults.Text = "Name saved. Refresh page to see changes."
Catch ex As ArgumentException
    tbResults.Text = ex.Message
End Try
try
{
    userSettings.Add("name", tbName.Text);
    tbResults.Text = "Name saved. Refresh page to see changes.";
}
catch (ArgumentException ex)
{
    tbResults.Text = ex.Message;
}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.