Skip to content

Latest commit

 

History

History
65 lines (46 loc) · 2.64 KB

deviceinformationcollection.md

File metadata and controls

65 lines (46 loc) · 2.64 KB
-api-id -api-type
T:Windows.Devices.Enumeration.DeviceInformationCollection
winrt class

Windows.Devices.Enumeration.DeviceInformationCollection

-description

Represents a collection of DeviceInformation objects.

-remarks

Successful completion of FindAllAsync results in a DeviceInformationCollection containing DeviceInformation objects.

Collection member lists

For JavaScript, DeviceInformationCollection has the members shown in the member lists. In addition, DeviceInformationCollection supports a length property, members of Array.prototype, and using an index to access items.

Enumerating the collection in C# or Microsoft Visual Basic

DeviceInformationCollection is enumerable, so you can use language-specific syntax such as foreach in C# to enumerate the items in the collection. The compiler does the type-casting for you and you won't need to cast to IEnumerable<DeviceInformation> explicitly. If you do need to cast explicitly, for example if you want to call GetEnumerator, cast to IEnumerable with a DeviceInformation constraint.

-examples

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;
}

-see-also