using System.Collections.Generic;
Dictionary<string, List<string>> dic = new Dictionary<string, List<string>>();
public static void Main()
const string _menuData ="marketing-,r&d-, supply chain-, products-marketing, planning-marketing, component-r&d, software-r&d, hardware-r&d, scm operations-supply chain, monitors-products, features-planning, amo-planning, prl-planning, find component-component, find irs component-component, features without roots-component,product explorer-software, scmx editor-software, software refresh-software,system rom component-hardware,lifecycle data management-scm operations, reports-, pulsar marketing-reports, amo matrix report-pulsar marketing, channel partner product configuration-pulsar marketing, channel partner usage-pulsar marketing, pulsar r&d-reports, Com. software erd-pulsar r&d, featurebyte decoder-pulsar r&d, hardware qual matrix-pulsar r&d, pulsar supply chain-reports, av action score card-pulsar supply chain, av product offering report-pulsar supply chain";
string[] allList = _menuData.Split(',');
List<KeyValuePair<string, string>> groups = new List<KeyValuePair<string, string>>();
foreach(string child in allList)
groups.Add(new KeyValuePair<string, string>(child.Substring(child.IndexOf("-")+1), child.Substring(0,child.IndexOf("-"))));
AddEntry(child.Substring(child.IndexOf("-")+1), child.Substring(0, child.IndexOf("-")));
List<string> childs = new Program().GetAllChild("marketing", groups);
Console.WriteLine(childs[0]);
public List<string> GetAllChild(string id,List<KeyValuePair<string, string>> newLst)
List<string> list = new List<string>();
for (int i = 0; i < newLst.Count; i++)
if (!list.Contains(newLst[i].Value))
list.Add(newLst[i].Value);
List<string> l = GetAllChild(newLst[i].Value, newLst);
private static void AddEntry(string parent, string child)
if (!new Program().dic.TryGetValue(parent, out children))
children = new List<string>();
new Program().dic[parent] = children;
private List<string> GetAllChildren(string parent)
List<string> children = new List<string>();
PopulateChildren(parent, children);
private void PopulateChildren(string parent, List<string> children)
if (new Program().dic.TryGetValue(parent, out myChildren))
children.AddRange(myChildren);
foreach (string child in myChildren)
PopulateChildren(child, children);