Dictionary.Value Property (BCL)
The Value property allows you to get or set a name/value pair in the Dictionary.
Definition
[Visual Basic .NET]
Public Property Value(bstrName As String) As Object
[C#]
public object this[ string aKey ] [get; set;]
Parameters
[Visual Basic .NET]
- bstrName
A String that contains the name of the Dictionary key for which to retrieve a value or put a value.
[C#]
aKey
A String that contains the name of the Dictionary key for which to retrieve a value or put a value.Value
When setting the value, an Object that contains the value to which the element specified by the key aKey should be initialized.
When getting the value, an Object containing the value of the key specified by the aKey index. If you stored something less general than an Object, you will have to cast the returned Object to get your saved type.Dictionary userDict = new Dictionary();
userDict[“creditCard”] = “Amex”; //set
string currentCard = (string) userDict[“creditCard”]; //get
Return Values
The get version of the indexer returns an Object.
Remarks
When using the get version of the indexer, if the key being accessed in the dictionary does not exist, an Object set to null is returned. Therefore, to logically delete a key from the dictionary, you can set the value for the key to DBNull.Value and then to a client of the dictionary. It is indistinguishable from a key/value pair that does not exist. The Value parameter contains valid data only if the property is accessed successfully.
[Visual Basic .NET]
Example
' dDict is a Dictionary object
' first_name is a Dictionary key
' o_first_name is an Object
o_first_name = dDict.Value("first_name")
o_first_name = dDict("first_name")
' use this form if the value contains an object reference:
oSubObject = dDict("myObjectKey")
' Property syntax
o_first_name = dDict.first_name
' If the key begins with an underscore then use braces around the key name
o_first_name = dDict.[_first_name]
Requirements
Namespace: Microsoft.CommerceServer.Runtime
Platforms: Windows 2000, Windows Server 2003
Assembly: mscscorelib (in mscscorelib.dll)
See Also
Copyright © 2005 Microsoft Corporation.
All rights reserved.