DeviceInformationCollection 類別

定義

表示 DeviceInformation 物件的集合。

public ref class DeviceInformationCollection sealed : IIterable<DeviceInformation ^>, IVectorView<DeviceInformation ^>
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class DeviceInformationCollection final : IIterable<DeviceInformation>, IVectorView<DeviceInformation>
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class DeviceInformationCollection : IEnumerable<DeviceInformation>, IReadOnlyList<DeviceInformation>
Public NotInheritable Class DeviceInformationCollection
Implements IEnumerable(Of DeviceInformation), IReadOnlyList(Of DeviceInformation)
繼承
Object Platform::Object IInspectable DeviceInformationCollection
屬性
實作

Windows 需求

裝置系列
Windows 10 (已於 10.0.10240.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)

範例

var DeviceInformation = Enumeration.DeviceInformation;
DeviceInformation.findAllAsync(deviceClass).then(
    successCallback, 
    errorCallback
);

// Handles successful completion of the findAllAsync method.
function successCallback(deviceInformationCollection) {
    var numDevices = deviceInformationCollection.length;
    document.getElementById("statusMessage").innerHTML = 
        numDevices + " device interface(s) found";
    if (numDevices) {
        for (var i = 0; i < numDevices; i++) {
            printFriendlyNameAndID(deviceInformationCollection[i], 
                document.getElementById("Output"));
        }
    } else {
        document.getElementById("statusMessage").innerHTML = "No devices found";
    }
}

// Handles an error completion of the findAllAsync method.
function errorCallback(e) {
    document.getElementById("statusMessage").innerHTML = 
        "Failed to find devices, error: " + e.message;
}

備註

FindAllAsync成功完成會導致 DeviceInformationCollection 包含DeviceInformation物件。

集合成員清單

針對 JavaScript,DeviceInformationCollection 具有成員清單中顯示的成員。 此外,DeviceInformationCollection 也支援 length 屬性、 Array.prototype的成員,以及使用索引來存取專案。

列舉 C# 或 Microsoft Visual Basic 中的集合

DeviceInformationCollection 是可列舉的,因此您可以使用 C# 中的 foreach 等語言特定語法來列舉集合中的專案。 編譯器會為您執行型別轉換,而且您不需要明確地轉換成 IEnumerable<DeviceInformation> 。 如果您需要明確轉換,例如,如果您想要呼叫GetEnumerator,請使用DeviceInformation條件約束轉換成IEnumerable < T >

屬性

Size

集合中的 DeviceInformation 物件數目。

方法

First()

取得物件,這個物件可以從第一個開始逐一查看列舉的 DeviceInformation 物件。

GetAt(UInt32)

取得位於指定索引處的 DeviceInformation 物件。

GetMany(UInt32, DeviceInformation[])

取得 DeviceInformation 物件的範圍。

IndexOf(DeviceInformation, UInt32)

傳回集合中指定 DeviceInformation 物件的索引。

適用於