ManagementObjectCollection.ManagementObjectEnumerator 类
定义
表示集合的枚举数。Represents the enumerator on the collection.
public: ref class ManagementObjectCollection::ManagementObjectEnumerator : IDisposable, System::Collections::IEnumerator
public class ManagementObjectCollection.ManagementObjectEnumerator : IDisposable, System.Collections.IEnumerator
type ManagementObjectCollection.ManagementObjectEnumerator = class
interface IEnumerator
interface IDisposable
Public Class ManagementObjectCollection.ManagementObjectEnumerator
Implements IDisposable, IEnumerator
- 继承
-
ManagementObjectCollection.ManagementObjectEnumerator
- 实现
示例
下面的示例将枚举Win32_LogicalDisk类的所有实例, 并显示每个实例的DeviceID值。The following example enumerates through all of the instances of the Win32_LogicalDisk class, and displays the DeviceID value for each instance.
using System;
using System.Management;
// This example demonstrates how to
// enumerate all logical disks
// using the ManagementObjectEnumerator object.
class Sample_ManagementObjectEnumerator
{
public static int Main(string[] args)
{
ManagementClass diskClass =
new ManagementClass("Win32_LogicalDisk");
ManagementObjectCollection disks =
diskClass.GetInstances();
ManagementObjectCollection.ManagementObjectEnumerator
disksEnumerator =
disks.GetEnumerator();
while(disksEnumerator.MoveNext())
{
ManagementObject disk =
(ManagementObject)disksEnumerator.Current;
Console.WriteLine(
"Disk found: " + disk["deviceid"]);
}
return 0;
}
}
Imports System.Management
' This sample demonstrates how to
' enumerate all logical disks
' using ManagementObjectEnumerator object.
Class Sample_ManagementObjectEnumerator
Public Overloads Shared Function _
Main(ByVal args() As String) As Integer
Dim diskClass As New _
ManagementClass("Win32_LogicalDisk")
Dim disks As ManagementObjectCollection = _
diskClass.GetInstances()
Dim disksEnumerator As _
ManagementObjectCollection. _
ManagementObjectEnumerator = _
disks.GetEnumerator()
While disksEnumerator.MoveNext()
Dim disk As ManagementObject = _
CType(disksEnumerator.Current, _
ManagementObject)
Console.WriteLine("Disk found: " & disk("deviceid"))
End While
Return 0
End Function
End Class
属性
Current |
获取该枚举数指向的当前 ManagementBaseObject。Gets the current ManagementBaseObject that this enumerator points to. |
方法
Dispose() |
释放与该对象关联的资源。Releases resources associated with this object. 调用该方法后,尝试使用该对象将导致引发 ObjectDisposedException 异常。After this method has been called, an attempt to use this object will result in an ObjectDisposedException exception being thrown. |
Equals(Object) |
确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object. (继承自 Object) |
Finalize() |
处置对象所保留的资源。Disposes of resources the object is holding. 这是该对象的析构函数。This is the destructor for the object. 使用析构函数语法表示终结器。Finalizers are expressed using destructor syntax. |
GetHashCode() |
用作默认哈希函数。Serves as the default hash function. (继承自 Object) |
GetType() |
获取当前实例的 Type。Gets the Type of the current instance. (继承自 Object) |
MemberwiseClone() |
创建当前 Object 的浅表副本。Creates a shallow copy of the current Object. (继承自 Object) |
MoveNext() |
指示枚举数是否已移到了枚举中的下一个对象。Indicates whether the enumerator has moved to the next object in the enumeration. |
Reset() |
将枚举数重置到集合的开头。Resets the enumerator to the beginning of the collection. |
ToString() |
返回一个表示当前对象的 string。Returns a string that represents the current object. (继承自 Object) |
显式界面实现
IEnumerator.Current |
获取集合中的当前对象。Gets the current object in the collection. |