Partager via


IMap<K, V> interface

Represents an associative collection.

Template parameters

  • K
    The type of the keys in the map.

  • V
    The type of the values in the map.

Members

The IMap<K, V> interface inherits from IInspectable. IMap also has these types of members:

  • Methods

Methods

The IMap<K, V> interface has these methods.

Method Description
Clear

Removes all items form the IMap.

get_Size

Gets the number of items in the IMap.

GetView

Returns an immutable view of the IMap.

HasKey

Determines whether the IMap contains the specified key.

Insert

Inserts or replaces an item in the IMap.

Lookup

Returns the item at the specified key in the IMap.

Remove

Removes an item form the IMap.

 

Remarks

The IMap interface represents a collection of key-value pairs in which a value can be accessed by its associated key. Properties and methods of IMap support dictionary-type functionality such getting the size of the collection and adding and removing items at specified locations in the collection. Additionally, the GetView method provides a snapshot of the map whose observable state does not change. The snapshot is useful when you need a view of the collection to refer to in subsequent operations that involve the IMap.

Examples

The following code example demonstrates how to use the IMap object and get a view of the map.

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

IMapView