Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Represents an associative collection, also known as a map or a dictionary.
.NET This interface appears to .NET code as System.Collections.Generic.IDictionary<TKey,TValue> due to .NET language projection. In any case where a Windows Runtime type has implemented IMap<K,V>, .NET code can use the APIs of IDictionary<TKey,TValue> instead.
public interface class IMap : IIterable<IKeyValuePair<K, V> ^>
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.FoundationContract, 65536)] /// [Windows.Foundation.Metadata.Guid(1009329662, 34073, 17857, 170, 121, 25, 123, 103, 24, 193, 193)] template <typename K, typename V> struct IMap : IIterable<IKeyValuePair<K, V>>
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.FoundationContract), 65536)] [Windows.Foundation.Metadata.Guid(1009329662, 34073, 17857, 170, 121, 25, 123, 103, 24, 193, 193)] public interface IDictionary<K,V> : IEnumerable<KeyValuePair<K,V>>
Public Interface IDictionary(Of K, V) Implements IEnumerable(Of KeyValuePair(Of K, V))
Windows 10 (introduced in 10.0.10240.0)
Windows.Foundation.FoundationContract (introduced in v1.0)
When programming with .NET, this interface is hidden and developers should use the System.Collections.Generic.IDictionary<TKey,TValue> interface if they want to implement a map/dictionary type. In any case where a Windows Runtime type has implemented IMap<K,V>, .NET code can use the APIs of IDictionary<TKey,TValue> instead. This includes all the existing Windows Runtime API and also scenarios such as using the APIs of Windows Runtime components originally implemented in Visual C++ component extensions (C++/CX) from a C# or Visual Basic app.
The IMap<K,V> interface represents a collection of key-value pairs where a value can be accessed by its associated key. Properties and methods of IMap<K,V> support dictionary-type functionality, such as 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 IMap<K,V>.
C++/WinRT extension functions
Extension functions exist on the C++/WinRT projection types for certain Windows Runtime APIs. For example, winrt::Windows::Foundation::IAsyncAction is the C++/WinRT projection type for IAsyncAction. The extension functions aren't part of the application binary interface (ABI) surface of the actual Windows Runtime types, so they're not listed as members of the Windows Runtime APIs. But you can call them from within any C++/WinRT project. See C++/WinRT functions that extend Windows Runtime APIs.
auto begin() const;
Returns an iterator to the first key-value pair of the collection, for use in C++ algorithms such as range-based
auto end() const;
Returns an iterator to one past the last key-value pair of the collection, for use in C++ algorithms such as range-based
auto TryLookup(param_type<K> const& key) const;
Tries to look up an element in the map with the key key. For reference types, returns the value if found, or
nullptr if not found. For value types, returns a std::optional<V>, which holds the value if found, or has no value if not found.
bool TryRemove(param_type<K> const& key) const;
Removes the element in the map with the key key, if present. Returns
true if the element was found and removed. Returns
false if the element was not found.
IMap<K,V> inherits IIterable, using an IKeyValuePair constraint that uses the same key and value types. Types that implement IMap<K,V> also implement the interface members of IIterable, with IKeyValuePair type constraint sharing the same key and value. Similarly, if you're using .NET, there is support for IEnumerabe<T>, with its constraint type as a KeyValuePair that uses the same key and value types as does the IDictionary<TKey,TValue> implementation.
Gets the number of items in the map.
Removes all items from the map.
Returns an immutable view of the map.
Determines whether the map contains the specified key.
Inserts or replaces an item in the map.
Returns the item at the specified key in the map.
Removes an item from the map.