c# - Recursively search nested lists -


i've read , searched , i'm yet figure out answer relatively simple issue.

i have class:

public class accessibletreeitem {     public string name;     public list<accessibletreeitem> children;      public accessibletreeitem()     {         children = new list<accessibletreeitem>();     } } 

which populate using series of functions don't matter in context, i'm looking way search through of children items in list, searching particular 'name' value, , if found, returning list.

how achieved in easiest manner, least performance hit? - i've been stumped @ point days now...

public class accessibletreeitem {     public string name;     public list<accessibletreeitem> children;      public accessibletreeitem()     {         children = new list<accessibletreeitem>();     }      public static accessibletreeitem find(accessibletreeitem node, string name)     {          if (node == null)             return null;          if (node.name == name)             return node;          foreach (var child in node.children)         {             var found = find(child, name);             if (found != null)                 return found;         }          return null;     } } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -