# List of Lists to Datatree - C# Nested Lists

**URL:** <https://discourse.mcneel.com/t/list-of-lists-to-datatree-c-nested-lists/62732>\
**Category:** Grasshopper Developer\
**Created:** [May 14, 2018, 8:59am UTC](https://discourse.mcneel.com/t/list-of-lists-to-datatree-c-nested-lists/62732 "2018-05-14T08:59:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Antonio\_Cersosimo](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/antonio_cersosimo/32/75712_2.png) [@Antonio\_Cersosimo](https://discourse.mcneel.com/u/Antonio_Cersosimo)\
**Post date:** [May 14, 2018, 8:59am UTC](https://discourse.mcneel.com/t/list-of-lists-to-datatree-c-nested-lists/62732/1 "2018-05-14T08:59:34Z")

</div>

Hi, here I am linking a Discussion in the old grasshopper forum about Datatrees, just because it took me a while to find it an I couldn’t find clear examples. An here is the function for converting from Nested Lists to Datatrees, that Andrew Heumann share in that discussion. Thanks

```
   DataTree<T> ListOfListsToTree<T>(List<List<T>> list){
       DataTree<T> tree = new DataTree<T>();
       int i = 0;
       foreach(List<T> innerList in list){
           tree.AddRange(innerList, new GH_Path(new int[]{0,i}));
           i++;
       }
   return tree;
   }

```

[http://www.grasshopper3d.com/forum/topics/list-of-lists-to-datatree](http://www.grasshopper3d.com/forum/topics/list-of-lists-to-datatree)

---

<div class="post-metadata">

**Author:** ![PeterFotiadis](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/peterfotiadis/32/472316_2.png) [@PeterFotiadis](https://discourse.mcneel.com/u/PeterFotiadis)\
**Post date:** [May 15, 2018, 7:58am UTC](https://discourse.mcneel.com/t/list-of-lists-to-datatree-c-nested-lists/62732/2 "2018-05-15T07:58:27Z")

</div>

You may find this recent thread interesting as well:

> [@DataTree to List of Lists (dynamic depth) c#](https://discourse.mcneel.com/t/datatree-to-list-of-lists-dynamic-depth-c/61830/30):
>
> Indeed. Consider for instance stuff where numbering of path dims has some critical meaning (the rule in AEC engineering) and you exchange data to/from Generative Components or some MCAD app (CATIA and the likes). BTW: LINQ (very handy I confess) is a bit slow for big N of items.

 ![Screen%20Shot%20010](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/1/1/1177a03d6dfa852b4ee6b8c9f9ad4624a9b58890.JPG)

 ![Screen%20Shot%20012](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/8/f/8fbcd7ded453d3d76fdbb2e5f6cc49d7d4ff617c.JPG)

 ![Screen%20Shot%20013](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/9/6/964bc9df4793beaa57db6bda6e5d61d69e739a38.JPG)

 ![Screen%20Shot%20014](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/6/2/62d5ec3836d4aab7d54bb073e47379dfbdaf2399.JPG)

 ![Screen%20Shot%20011](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/3/4/345dcec761f6ca5744c8f31f3b63117f0755e1bb.JPG)
