ManagementObjectCollection.ManagementObjectEnumerator ManagementObjectCollection.ManagementObjectEnumerator ManagementObjectCollection.ManagementObjectEnumerator ManagementObjectCollection.ManagementObjectEnumerator Class

定義

表示集合上的列舉值。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.ManagementObjectEnumeratorManagementObjectCollection.ManagementObjectEnumeratorManagementObjectCollection.ManagementObjectEnumeratorManagementObjectCollection.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
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 Current Current Current

取得這個列舉值指向的目前 ManagementBaseObjectGets the current ManagementBaseObject that this enumerator points to.

方法

Dispose() Dispose() Dispose() 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) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
Finalize() Finalize() Finalize() Finalize()

處置物件所保有的資源。Disposes of resources the object is holding. 這是物件的解構函式。This is the destructor for the object. 完成項會使用解構函式語法來表示。Finalizers are expressed using destructor syntax.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
MoveNext() MoveNext() MoveNext() MoveNext()

指出列舉值是否已經移至列舉中的下一個物件。Indicates whether the enumerator has moved to the next object in the enumeration.

Reset() Reset() Reset() Reset()

將列舉值重設為集合的開頭。Resets the enumerator to the beginning of the collection.

ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

明確介面實作

IEnumerator.Current IEnumerator.Current IEnumerator.Current IEnumerator.Current

取得集合中目前的物件。Gets the current object in the collection.

適用於