using System.DirectoryServices; DirectoryEntry entry = new DirectoryEntry("LDAP://CN=JohnDoe,DC=mydomain,DC=com"); DirectorySearcher searcher = new DirectorySearcher(entry); searcher.Filter = "(objectClass=user)"; SearchResult result = searcher.FindOne(); if(result != null) { Console.WriteLine("User Found"); Console.WriteLine("Name: " + result.Properties["name"][0].ToString()); Console.WriteLine("Email: " + result.Properties["mail"][0].ToString()); } else { Console.WriteLine("User Not Found"); }In this example, we create a DirectoryEntry object for the user "JohnDoe" in the "mydomain.com" domain and use a DirectorySearcher object to search for all objects of type "user". The FindOne() method is called to find the first user object that matches the search criteria. If a result is found, we print the user's name and email address. The package library for this code is the System.DirectoryServices assembly, which is included in the .NET Framework Class Library.