[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Gets or sets the value associated with the specified key.
Assembly: System.Windows (in System.Windows.dll)
- Type: System.String
The key of the item to get or set.
Property ValueType: System.Object
The value associated with the specified key. If the specified key is not found, a get operation throws a KeyNotFoundException, and a set operation creates a new element that has the specified key.
This property provides the ability to access a specific element in the collection by using the following syntax:
myCollection("key") (Visual Basic)
You can also use the property to add new elements by setting the value of a key that does not exist in the Dictionary<TKey, TValue>. For example, use the following syntax to add a new element:
myCollection["myNonexistentKey"] = myValue (C#)
myCollection("myNonexistentKey") = myValue (Visual Basic)
A key cannot be null, but a value can be if the value type TValue is a reference type.
The following example saves a string value from a TextBox named tbName to a user setting called name. It then accesses the saved name and uses it to display a personalized greeting in a TextBox named tbResults. If the name key does not exist, the "Hello, World" greeting is displayed instead. This example is part of a larger example for the IsolatedStorageSettings class.