我有以下代码:
// Create a DirectorySearcher object.
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.SearchScope = SearchScope.Base;
// Use the FindOne method to find the user object.
SearchResult resEnt = mySearcher.FindOne();
foreach(string propKey in resEnt.Properties.PropertyNames)
{
foreach (var property in resEnt.Properties[propKey])
{
Console.WriteLine("{0}:{1}", propKey, property.ToString());
}
}
这很好用,但我只需要获得一个名为“mail”的属性。无论如何我可以只读取一个属性而不必循环。我正在寻找这样的东西:
var emailAddress = resEnt.Properties["mail"];