ManagementBaseObject.Item[String] 屬性

定義

經由 [] 標記取得屬性值的存取。Gets access to property values through [] notation. 這個屬性就是 ManagementBaseObject 類別的索引子 (Indexer)。This property is the indexer for the ManagementBaseObject class. 您可以使用型別所定義的預設索引屬性,但是您無法明確地定義自己的屬性。You can use the default indexed properties defined by a type, but you cannot explicitly define your own. 然而,在類別上指定 expando 屬性會自動提供預設索引屬性,它的類型為 Object,而索引類型為 String。However, specifying the expando attribute on a class automatically provides a default indexed property whose type is Object and whose index type is String.

public:
 property System::Object ^ default[System::String ^] { System::Object ^ get(System::String ^ propertyName); void set(System::String ^ propertyName, System::Object ^ value); };
public object this[string propertyName] { get; set; }
member this.Item(string) : obj with get, set
Default Public Property Item(propertyName As String) As Object

參數

propertyName
String

相關的屬性名稱。The name of the property of interest.

屬性值

Object

特定類別屬性的管理物件。The management object for a specific class property.

範例

下列範例顯示如何使用函式初始化 ManagementClass 變數 ManagementClass ,然後取得 WMI 類別的所有實例。The following example shows how to initialize a ManagementClass variable with a ManagementClass constructor and then get all the instances of a WMI class.

using System;
using System.Management;

public class Sample
{
    public static void Main()
    {
        ManagementClass c = new ManagementClass("Win32_Process");
        foreach (ManagementObject o in c.GetInstances())
            Console.WriteLine(
                "Next instance of Win32_Process : {0}", o["Name"]);
    }
}
Imports System.Management


Class Sample
    Public Overloads Shared Function _
        Main(ByVal args() As String) As Integer

        Dim c As New ManagementClass("Win32_Process")
        Dim o As ManagementObject
        For Each o In c.GetInstances()
            Console.WriteLine( _
                "Next instance of Win32_Process : {0}", o("Name"))
        Next o

    End Function
End Class

備註

屬性值Property Value

物件實例,其中包含所要求之屬性的值。An object instance that contains the value of the requested property.

.NET Framework 安全性.NET Framework Security

完全信任立即呼叫者。Full trust for the immediate caller. 這個成員無法供部分信任的程式碼使用。This member cannot be used by partially trusted code. 如需詳細資訊,請參閱從部分信任的程式碼使用程式庫For more information, see Using Libraries from Partially Trusted Code.

適用於