如何使用递归函数将数据从字典加载到列表框中

编程入门 行业动态 更新时间:2024-10-26 12:27:38
本文介绍了如何使用递归函数将数据从字典加载到列表框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有人可以告诉我如何在列表框中调用递归函数吗? 我有一个名为lrg_prod的用户组,其中包含50个员工名称.我必须将这些雇员的姓名加载到前端屏幕的列表框中. 我的功能GetUsersByGroup是这样的:

Hi, Can anybody please tell me how to call a recursive function in list box? I have a user group by name lrg_prod, which contains 50 employee names. I have to load these employee''s names into a list box of my front end screen. my function GetUsersByGroup is like this:

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; }

我的前端屏幕上的newusergroup.cs文件代码是这样的:

and my frontend screen newusergroup.cs file code is like this:

public NewUserGroup() { string strGroupName = "lrg_prod"; string[] employees = Helper.GetUsersByGroup(strGroupName); foreach(string employee in employees) { lbUsersList.Items.Add(employee); } }

推荐答案

虽然我看不到递归,但是您似乎向我们展示了甚至没有编译的代码.您的函数GetUsersByGroup返回一个Dictionary,然后在您的前端代码中尝试将其存储到字符串数组中. 如果代码不合适,请不要退出:再试一次,请指出使用递归函数"是什么意思,您现在让我感到好奇. :) 干杯, 曼弗雷德(Manfred) No recursion in sight however I look at it, but you seem to be showing us code that doesn''t even compile. Your function GetUsersByGroup returns a Dictionary and in your front end code you try to store that into a string array. If the code doesn''t fit, don''t just quit: Try again and please point out what you mean by "using recursive function", you''ve gotten me curious now. :) Cheers, Manfred

看看您的问题标题,我认为您不希望使用for循环向ListBox添加项目吗?您想使用递归函数向其中添加项目吗? 但是有两点需要考虑: 1)如果要使用递归函数,则不能使用Constructor进行递归. 2)函数GetUsersByGroup的返回类型为Dictionary< type,>.但是在构造函数中,您将其设置为string []类型.这是不正确的. 如果要使用递归,请尝试: 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));//lbUsersList.Items.Add(employees.ElementAt(count).Key); } if (count > 0) { AddItems(); } else { return; } }

如果要使用递归函数,请不要使用Constructor添加项. 希望对您有帮助. 安迪

Don''t use Constructor to add items if you want to use recursive function. Hope it helps you. Andy

安迪,你好, Hi Andy, I used the above code, but i cant able to declare public or static modifier in my function, it is showing as a invalid expression term, i can use only the default modifier, but it is loading the data of one record..

Because am not able to call AddItems()function inside the second if condition, as the declaration is giving error..

您将如何帮助我加载所有员工数据.

So will u pls help how can i do this to load all the employees data.

if it is in a loop it would be helpful..

即使我尝试了while和while循环,但是它在我的应用程序中都为上述功能提供了例外,因此您能否告诉我如何做到这一点...

even i tried for and while loop but it is giving exception for the above functionality in my application, so will u pls tell me how can i do this...

更多推荐

如何使用递归函数将数据从字典加载到列表框中

本文发布于:2023-07-16 16:12:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1123438.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:递归   如何使用   框中   字典   函数

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!