Look at your title of the question, I think that you don't want to add items to ListBox with for loop? And you want to use recursive function to add items into it?
But there are 2 points need to consider:
1) If you want to use recursive function, you cannot use Constructor for recursion.
2) The function GetUsersByGroup has return type is Dictionary<type,>. But in the constructor you set it to string[] type. It's not correct.
If you want to use recursive, please try:
public static Dictionary<string,> GetUsersByGroup(string group)
{
Search s = new FWD2Search { Username = DataKey.ldapCredentialValue, Password = DataKey.ldapPassword };
Group grp = s.GetGroup(group);
Dictionary<string,> list = grp.PeopleInGroup;
return list;
}
And
private const string strGroupName = "lrg_prod";
private static Dictionary<string, > employees = GetUsersByGroup(strGroupName);
private static int count = employees.Count;
public static void AddItems()
{
count--;
if(count >= 0){ lbUsersList.Items.Add(employees.ElementAt(count));
}
if (count > 0)
{
AddItems();
}
else
{
return;
}
}
Don't use Constructor to add items if you want to use recursive function.
Hope it helps you.
Andy