Skip to main content
ApplicationDataContainerSettings.Add method

Applies to Windows and Windows Phone

Adds a new item to the ApplicationDataContainerSettings.

Syntax


public void Add(
  string key, 
  object value
)

Public Sub Add(
  key As String,  
  value As Object 
)

Parameters

key

Type: System.String

The key of the new item to add.

value

Type: System.Object

The value of the new item to add.

Examples

The following example shows how to add an app setting by using either the Add(String, Object) or the Add(KeyValuePair)method. It also shows how to iterate over the app settings and how to access the value of an individual setting.


using Windows.Storage;
using System.Diagnostics; // For writing results to the Output window.
...
            // Get the app's application data.
            ApplicationData appData = ApplicationData.Current;

            // Get the data container of local settings.
            ApplicationDataContainer appLocalSettingsContainer =
                appData.LocalSettings;

            // Get the local settings and their values.
            ApplicationDataContainerSettings appLocalSettings =
                (ApplicationDataContainerSettings)appLocalSettingsContainer.Values;

            // Clear the settings for this example.
            appLocalSettings.Clear();

            // Add a setting by providing the key and the value separately.
            appLocalSettings.Add("key1", "value1");

            // Add another setting by providing a key-value pair.
            appLocalSettings.Add(new KeyValuePair<String, Object>("key2", "value2"));

            // Write the number of settings to the Visual Studio Output window.
            Debug.WriteLine("Number of local settings: " + appLocalSettings.Count.ToString());

            // Write the settings to the Output window.
            foreach (KeyValuePair<string, object> setting in appLocalSettings)
            {
                //KeyValuePair<string, object> kvp = (KeyValuePair<string, object>)setting;
                Debug.WriteLine(setting.Key + ", " + setting.Value);
            }

            // Write the value of the "key1" setting.
            Debug.WriteLine("The value of key1 is = " + appLocalSettings["key1"].ToString());

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Namespace

Windows.Storage

See also

ApplicationDataContainerSettings