Windows Dev Center

EN
Este conteúdo não está disponível em seu idioma, mas aqui está a versão em inglês.

IMap<K, V> interface

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.

Syntax


generic<typename K, typename V>
public interface class IMap : IIterable<IKeyValuePair>

Type parameters

K

The type of the keys in the map.

V

The type of the values in the map.

Members

The IMap interface inherits from IIterable(IKeyValuePair). IMap also has these types of members:

Methods

The IMap interface has these methods. It also inherits methods from the Object class.

MethodDescription
Clear Removes all items from the map.
GetView Returns an immutable view of the map.
HasKey Determines whether the map contains the specified key.
Insert Inserts or replaces an item in the map.
Lookup Returns the item at the specified key in the map.
Remove Removes an item from the map.

 

Properties

The IMap interface has these properties.

PropertyAccess typeDescription

Size

Read-onlyGets the number of items in the map.

 

Remarks

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

Interface inheritance

IMap<K,V> inherits IIterable<T>, 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<T>, with IKeyValuePair type constraint sharing the same key and value. 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 IDictionary<TKey,TValue> implementation.

Requirements (Windows 10 device family)

Device family

Universal

API contract

Windows.Foundation.FoundationContract, introduced version 1.0

Namespace

Windows::Foundation::Collections

Metadata

Windows.Foundation.FoundationContract.winmd

Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8

Namespace

Windows::Foundation::Collections

Metadata

Windows.winmd

Attributes

[Version(0x06020000)]

See also

IIterable(IKeyValuePair)
Collections (C++/CX)
System.Collections.Generic.IDictionary<TKey,TValue>

 

 

Mostrar:
© 2015 Microsoft