IMapView<K,V> 接口

定义

表示地图中的不可变视图。

。网 由于 .NET 语言投影,此接口显示为 System.Collections.Generic.IReadOnlyDictionary<TKey,TValue> 。 在Windows 运行时类型已实现 IMapView<K,V> 的情况下,.NET 代码都可以改用 IReadOnlyDictionary<TKey,TValue> 的 API。

public interface class IMapView : IIterable<IKeyValuePair<K, V> ^>
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.FoundationContract, 65536)]
/// [Windows.Foundation.Metadata.Guid(3833646656, 41784, 19162, 173, 207, 39, 34, 114, 228, 140, 185)]
template <typename K, typename V>
struct IMapView : IIterable<IKeyValuePair<K, V>>
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.FoundationContract), 65536)]
[Windows.Foundation.Metadata.Guid(3833646656, 41784, 19162, 173, 207, 39, 34, 114, 228, 140, 185)]
public interface IReadOnlyDictionary<K,V> : IEnumerable<KeyValuePair<K,V>>
Public Interface IReadOnlyDictionary(Of K, V)
Implements IEnumerable(Of KeyValuePair(Of K, V))

类型参数

K
V
属性
实现

Windows 要求

设备系列
Windows 10 (在 10.0.10240.0 中引入)
API contract
Windows.Foundation.FoundationContract (在 v1.0 中引入)

注解

使用 .NET 编程时,此接口是隐藏的,如果开发人员想要实现只读映射/字典类型,则应使用 System.Collections.Generic.IReadOnlyDictionary<TKey,TValue> 接口。 在Windows 运行时类型已实现 IMapView<K,V> 的情况下,.NET 代码都可以改用 IReadOnlyDictionary<TKey,TValue> 的 API。 这包括所有现有的 Windows 运行时 API,以及使用最初通过 C# 或 Visual Basic 应用以 C++ 实现的Windows 运行时组件的 API 等方案。

IMapView<K,V> 接口表示键值对的集合,其中值可由其关联的键访问。 IMapView<K,V> 的属性和方法支持字典类型功能,例如获取集合的大小或查找,但不支持添加或删除项,因为映射是只读的。

C++/WinRT 扩展函数

注意

某些Windows 运行时 API 的 C++/WinRT 投影类型上存在扩展函数。 例如, winrt::Windows::Foundation::IAsyncActionIAsyncAction 的 C++/WinRT 投影类型。 扩展函数不是应用程序二进制接口 (ABI) 实际Windows 运行时类型的图面的一部分,因此它们不会列为Windows 运行时 API 的成员。 但可以从任何 C++/WinRT 项目中调用它们。 请参阅扩展Windows 运行时 API 的 C++/WinRT 函数

auto begin() const;

返回集合的第一个键值对的迭代器,以便在 C++ 算法(如基于 for 范围的循环)中使用。

auto end() const;

返回一个迭代器,该迭代器指向集合的最后一个键值对之后的迭代器,以便在 C++ 算法(如基于 for 范围的循环)中使用。

auto TryLookup(param_type<K> const& key) const;

尝试 使用键查找映射中的元素。 对于引用类型,如果找到,则返回值,如果未找到, nullptr 则返回值。 对于值类型, 返回 std::optional<V>,如果找到该值,则保留值;如果未找到,则不具有任何值。

接口继承

IMapView 使用 IKeyValuePair 约束继承 IIterable。 实现 IMapView 的类型还使用 IKeyValuePair 类型约束实现 IKeyValuePair 的接口成员。 同样,如果使用 .NET,则支持 IEnumerable;T>,其约束类型为 KeyValuePair ,使用与 IReadOnlyDictionary<TKey,TValue> 实现相同的键和值类型。

属性

Size

获取映射中的元素数。

方法

HasKey(K)

确定地图视图是否包含指定的键。

Lookup(K)

返回地图视图中指定键处的项。

Split(IMapView<K,V>, IMapView<K,V>)

将地图视图拆分为两个视图。

适用于

另请参阅