0

Wording in my previous question prevented people from answering it. Regardless to say, I can do what I need to do. My ultimate concern is which option is optimal?

I am traversing the entire Active Directory for the domain and filtering it down by people/users.

I then need to throw this information into a collection.

I know I can do it with

List<Users>  // Create a model with the information i need and populate it.
Dictionary<string, List<Users>> // add a list of users to the string/department
Dictionary<string, Users> // struct or class
Lookup<string, Users>

I'm more looking for the optimal way, as going the Active Directory can be slow by it self I'm looking to optimize my code in other areas.

I only need the department stored a single time, and each department can have many different users.

What is the most optimal method to choose in this instance?

Edit Addition:

The only reason I need this specific code is for a specific page which will eventually allow me to loop through the contents and build out a drop down list. This code will not be used any where else.

4

1 回答 1

2

通过索引或扫描写入或访问时,列表会更快。

通过键(O(1) 而不是列表中的 O(N) 或 O(log N))访问项目时,字典会更快。

如果您尝试将所有用户添加到下拉框中,请使用List<User>.

如果您要将所有部门添加到下拉框中,并将该部门的用户添加到不同的下拉列表中Dictionary<Department, List<User>>,则可能会进行一些分析以查看单独的部门列表是否有意义。

如果您要在每次访问页面时重新创建集合,您将需要使用实际数据进行一些分析,以查看哪个性能更好。

编辑:根据您的更新,类似的东西怎么样

class Department
{
    public string Name {get;set;}
    public List<User> Users {get;set;}
}

List<Department> departments;

foo()
{
   foreach(department in departments)
   {
       // emit optgroup
       foreach(user in department.Users)
       {
           // emit option
       }
       // emit /optgroup
   }
}

或者更好的是缓存生成的 HTML。

于 2013-05-22T22:03:39.733 回答