共用方式為


IMap::Lookup method

Returns the item at the specified key in the IMap.

Syntax

HRESULT Lookup(
  [in]  K key,
  [out] V *value
);

Parameters

  • key [in]
    Type: K

    The key to use to locate the item in the IMap.

  • value [out]
    Type: V*

    The item associated with the specified key.

Return value

Type: HRESULT

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

Remarks

Use the HasKey method to determine if the key exists in the map.

Examples

The following code example demonstrates how to use the Lookup 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