IMap::HasKey method

Determines whether the IMap contains the specified key.

Syntax

HRESULT HasKey(
  [in]  K       key,
  [out] boolean *found
);

Parameters

  • key [in]
    Type: K

    The key to locate in the IMap.

  • found [out]
    Type: boolean*

    TRUE if the key is found; otherwise, FALSE.

Return value

Type: HRESULT

If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Examples

The following code example demonstrates how to use the HasKey method.

comptr<IMap<HSTRING,IValue>> pMap;
HSTRING hKey;
//...

comptr<IMapView<HSTRING,IValue>> pMapView;
HRESULT hr = pMap->GetView(&pMapView);
if (SUCCEEDED(hr))
{
    bool bHasKey
    hr = pMapView->HasKey(hKey, &bHasKey);
    if (SUCCEEDED(hr) && bHasKey)
    {
        comptr<IValue> pValue;
        hr = pMapView->Lookup(hKey, &pValue);
        if (SUCCEEDED(hr))
        {
            //...
        }
    }
}

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Header

Windows.Foundation.Collections.h

See also

IMap