Bagikan melalui


PropertyDictionary.TryGetValue Method

Determines if a value for the specified key exists in the PropertyDictionary.

Syntax

'Declaration
Public Function TryGetValue ( _
         key As String, _
         out value As Object _
) As Boolean 
public bool TryGetValue (
         string key,
         out Object value
)
public:
bool TryGetValue(
         String key,
         out Object value
)

Parameters

  • key
    Type: String
    The key to search for in the PropertyDictionary.
  • value
    Type: Object
    [OutAttribute] When the method returns, this parameter will contain the value associated with the specified key. If no value could be found in the PropertyDictionary, it will contain the default value for the type passed in.

Return Value

Type: Boolean
Returns true if the PropertyDictionary contains a value associated with the specified key; false otherwise.

Remarks

If the key is not found, then the value parameter gets the appropriate default value for the value type passed in. For example: 0 (zero) for integer types, false for Boolean types, and null for reference types.

Use the TryGetValue method if your code frequently attempts to access keys that are not in the dictionary. Using this method is more efficient than catching the KeyNotFoundException thrown by the Item property.

Requirements

Namespace: Microsoft.Xna.Framework.GamerServices

Assembly: Microsoft.Xna.Framework.GamerServices (in microsoft.xna.framework.gamerservices.dll)

See Also

Reference

PropertyDictionary Class
PropertyDictionary Members
Microsoft.Xna.Framework.GamerServices Namespace

Platforms

Windows Phone