共用方式為


讀取具有多個值的屬性

本主題提供讀取包含多重值的屬性的資訊與程式碼範例。如同包含單一值的屬性,可以使用 Value 屬性 (來自 PropertyValueCollection 物件) 讀取具有多重值的屬性。

對於包含多重值的屬性,請使用 foreach 陳述式擷取 Properties 集合,或使用陣列來列舉屬性值。

下列程式碼範例使用 Properties 集合來讀取多重值。

Dim ent As New DirectoryEntry("LDAP://Fabrikam/CN=My Username,CN=Users,DC=Fabrikam,DC=com")
Dim s As [String]
For Each s In ent.Properties("otherTelephone")
    Console.WriteLine(s)
Next
DirectoryEntry ent = new DirectoryEntry("LDAP://Fabrikam/CN=My Username,CN=Users,DC=Fabrikam,DC=com");
foreach(String s in ent.Properties["otherTelephone"] )
{
     Console.WriteLine(s);
} 

下列程式碼範例使用陣列來讀取值。

Dim ent As New DirectoryEntry("LDAP://Fabrikam/CN=My Username,CN=Users,DC=Fabrikam,DC=com")
If (True) Then
    Console.WriteLine(ent.Properties("otherTelephone")(2))
End If
DirectoryEntry ent = new DirectoryEntry("LDAP://Fabrikam/CN=My Username,CN=Users,DC=Fabrikam,DC=com");
{
     Console.WriteLine(ent.Properties["otherTelephone"][2]);
}

請參閱

參考

System.DirectoryServices
PropertyValueCollection
DirectoryEntry

概念

具有多個值的屬性

Send comments about this topic to Microsoft.

Copyright © 2007 by Microsoft Corporation.All rights reserved.