Hi!
I need to do a foreach to find all my subordinates and that includes to find all of the subordinates of my subordinates and so on...
I was trying to accomplish but I couldn't pass to find the 2nd level of subordinates...
Thanks!!
Hi!
I need to do a foreach to find all my subordinates and that includes to find all of the subordinates of my subordinates and so on...
I was trying to accomplish but I couldn't pass to find the 2nd level of subordinates...
Thanks!!
Something like the following?
object RecursiveCall(Collection collection, object itemToFind)
{
foreach(var item in collection)
{
if(item == itemToFind)
{
return item;
}
else
{
RecursiveCall(item, itemToFind);
}
}
}
private IEnumerable<Employee> RecursiveGet(Employee durr)
{
foreach(var sub in durr.Subordinates)
{
yield return sub;
foreach(var recurse in RecursiveGet(sub))
yield return recurse;
}
}
PSUDO:
private List<Subordinate> GetSubordinates(Subordinate you){
List<Subordinate> subs = new List<Subordinate>();
if(!you.HasSubordinates){
return subs;
}
foreach(Subordinate s in you.Subordinates){
subs.AddRange(GetSubordinates(s));
}
}