开发者

adding list items into list in c#

开发者 https://www.devze.com 2023-01-01 09:50 出处:网络
i have an list with data like this name|school |parent --------+-------+------- kumar|fes|TOP manju|fes|kumar

i have an list with data like this

name    |school |parent
--------+-------+-------
kumar   |fes    |TOP
manju   |fes    |kumar
anu     |frank  |kumar
anitha  |jss    |TOP
rohit   |frank  |manju
anill   |vijaya |manju
vani    |jss    |kumar
soumya  |jss    |kumar
madhu   |jss    |rohit
shiva   |jss    |rohit
vanitha |jss    |anitha
anu     |jss    |anitha

Code:

List<EMP> obj2 = new List<EMP>();
List<EMP> obj3 = new List<EMP>();
List<EMP> obj4 = new List<EMP>();

string [] strnames= {"Top","kumar","Anu","manju"};

//what i am  doing here is that in the string array i have the names of the string.
obj2 = ObjEmp.Where(p1 => p1.Parent == "Top").ToList();
obj3 = ObjEmp.Where(p1 => p1.Parent == "kumar").ToList();
obj4 = ObjEmp.Where(p1 => p1.Parent == "manju ").ToList();

here obj2 = ObjEmp.Where(p1 => p1.Parent == "Top").ToList(); here in obj2 will be filled with data(kumar fes TOP,anitha jss TOP) with these two data.

now row kumar has further data obj3 =ObjEmp.Where(p1 => p1.Parent == "kumar").ToList();

here wat get some more data.what we need to do here is that we need to take data from

obj3 and then add those data in obj2[]. and also make sure that we add the obj3

data in obj2.

here as obj2 will be filled with datalike{obj2[0],obj2[1],obj2[2],obj2[3]}

here we again need to check where under which object should we place开发者_运维百科 the data

hope my question is clear? anyhelp would be great thanks


If I understand you correctly, you want to build a tree out of your data. There is not inbuilt collection type for trees, so you need to implement your own. Dan Vanderboom shows how this could be done in his blog.

And no, your question is not clear. =)

0

精彩评论

暂无评论...
验证码 换一张
取 消