Поделиться через


IMap::Remove method

Removes an item form the IMap.

Syntax

HRESULT Remove(
  [in] K key
);

Parameters

  • key [in]
    Type: K

    The key associated with the item to remove.

Return value

Type: HRESULT

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

Error codes

The Remove method returns error codes that include, but are not limited to, those in the following table.

Name Meaning
E_BOUNDS

The key does not exist.

Remarks

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

Examples

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

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

bool bReplaced;
HRESULT hr = pMap->Insert(hKey, 123, &bReplaced);
//...

bool bHasKey;
hr = pMap->HasKey(hKey, &bHasKey);
if (SUCCEEDED(hr) && bHasKey)
{
    hr = pMap->Remove(hKey);
    if (SUCCEEDED(hr))
    {
        //...
    }
}

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Header

Windows.Foundation.Collections.h

See also

IMap