Share via


Reading Properties with Multiple Values

This topic provides information and code examples for reading properties that contain multiple values. As with properties that contain a single value, properties with multiple values are read using the Value property from the PropertyValueCollection object.

For properties that contain multiple values, use either a foreach statement to retrieve a Properties collection, or enumerate property values using an array.

The following code example uses the Properties collection to read multiple values.

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);
} 

The following code example uses an array to read values.

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]);
}

See Also

Reference

System.DirectoryServices
PropertyValueCollection
DirectoryEntry

Concepts

Properties with Multiple Values

Send comments about this topic to Microsoft.

Copyright © 2007 by Microsoft Corporation. All rights reserved.