Bagikan melalui


PropertyDictionary.TryGetValue Method

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

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

Syntax

public bool TryGetValue (
         string key,
         out Object value
)

Parameters

  • key
    The key to search for in the PropertyDictionary.
  • value
    [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

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.

See Also

Reference

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

Platforms

Xbox 360, Windows 7, Windows Vista, Windows XP, Windows Phone 7