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


IMap::Insert method

Inserts or replaces an item in the IMap.

Syntax

HRESULT Insert(
  [in]  K       key,
  [in]  V       value,
  [out] boolean *replaced
);

Parameters

  • key [in]
    Type: K

    The key associated with the item to insert.

  • value [in]
    Type: V

    The item to insert.

  • replaced [out]
    Type: boolean*

    TRUE if an item with the specified key is an existing item and was replaced otherwise, FALSE if an item with the specified key is not found in the map.

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 Insert 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