读取包含多个值的属性

本主题提供有关读取包含多个值的属性信息和代码示例。与包含单个值的属性一样,包含多个值的属性也是使用 PropertyValueCollection 对象中的 Value 属性读取的。

对于包含多个值的属性,使用 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.

版权所有 (C) 2007 Microsoft Corporation。保留所有权利。