title: Recursive method using List
body: <p>Within an asp.net application I have a list of categories objects, within this list each category can be a parent of another category.</p>
  
  <p>Example:</p>
  
  <pre><code>catid 1 catname cat1 parentid null
  catid 2 catname cat2 parentid null
  catid 3 catname cat3 parentid 2
  catid 4 catname cat4 parentid 2
  catid 5 catname cat5 parentid 4
  catid 6 catname cat6 parentid 5
  catit 7 catname cat7 parentid 5
  </code></pre>
  
  <p>I want to write a method that loops through the list of categories, pulls out the parent categories and acquires the child categories from the list.
  Doing this is easy the hard part I am having problems with is how do I know when the last category object has been reached within a recursive method.</p>
  
  <p>This is the logic I am looking for</p>
  
  <pre><code>protected void load_categories(ref List&lt;category&gt; list, category item)
  {
       //loop through list and match item ID with list item parent ID
       //loop through child items of category item using load_categories()
       //HOW DO I STOP ONCE EVERYTHING IS DONE?
  }
  </code></pre>