Skip to content

Latest commit

 

History

History
53 lines (35 loc) · 4.24 KB

imapview_2.md

File metadata and controls

53 lines (35 loc) · 4.24 KB
-api-id -api-type
T:Windows.Foundation.Collections.IMapView`2
winrt interface

Windows.Foundation.Collections.IMapView<K, V>

-description

Represents an immutable view into a map.

.NET This interface appears as System.Collections.Generic.IReadOnlyDictionary<TKey,TValue> due to .NET language projection. In any case where a Windows Runtime type has implemented IMapView<K,V>, .NET code can use the APIs of IReadOnlyDictionary<TKey,TValue> instead.

-remarks

When programming with .NET, this interface is hidden and developers should use the System.Collections.Generic.IReadOnlyDictionary<TKey,TValue> interface if they want to implement a read-only map/dictionary type. In any case where a Windows Runtime type has implemented IMapView<K,V>, .NET code can use the APIs of IReadOnlyDictionary<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 C++ from a C# or Visual Basic app.

The IMapView<K,V> interface represents a collection of key-value pairs where a value can be accessed by its associated key. Properties and methods of IMapView<K,V> support dictionary-type functionality, such as getting the size of the collection, or lookups, but don't support adding or removing items because the map is read-only.

C++/WinRT extension functions

Note

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 for loops.

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 for loops.

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.

Interface inheritance

IMapView inherits IIterable, using an IKeyValuePair constraint. Types that implement IMapView also implement the interface members of IKeyValuePair, with an IKeyValuePair type constraint. Similarly, if you're using .NET, there is support for IEnumerable;T>, with its constraint type as a KeyValuePair that uses the same key and value types as does the IReadOnlyDictionary<TKey,TValue> implementation.

-examples

-see-also

IReadOnlyDictionary<TKey,TValue>, Collections (C++/CX)