Consider the following code:
var results = searcher.FindAll();
SearchResult[] srList = new SearchResult[results.Count];
results.CopyTo(srList, 0);
where searcher.FindAll() returns a System.DirectoryServices.SearchResultCollection.
Do I have to use the CopyTo to get them into an enumerable that I can then later use in a Parallel.ForEach? And if so, why?
I have using System.Linq but there isn't a ToList method popping up.
Thanks all!
You can use Cast<T>() to cast a SearchResultCollection to IEnumerable<T>, and ToArray<T>() to create an array.
SearchResult[] results = searcher.FindAll().Cast<SearchResult>().ToArray();
Make sure you include the System.Linq namespace:
using System.Linq;
You can use the Cast<T> extension method to go from a non-generic IEnumerable to an IEnumerable<SearchResult>:
var results = searcher.FindAll().Cast<SearchResult>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With