# How to split a tree by the first index in C#

**URL:** <https://discourse.mcneel.com/t/how-to-split-a-tree-by-the-first-index-in-c/77819>\
**Category:** Grasshopper Developer\
**Created:** [January 24, 2019, 5:09pm UTC](https://discourse.mcneel.com/t/how-to-split-a-tree-by-the-first-index-in-c/77819 "2019-01-24T17:09:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Baris](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/baris/32/759711_2.png) [@Baris](https://discourse.mcneel.com/u/Baris)\
**Post date:** [January 24, 2019, 5:09pm UTC](https://discourse.mcneel.com/t/how-to-split-a-tree-by-the-first-index-in-c/77819/1 "2019-01-24T17:09:53Z")

</div>

Hi all,

could anybody give an example of how to split a tree by the first index in C#? Would be really appreciated

Like this:

 ![splittes](https://global.discourse-cdn.com/mcneel/original/3X/0/d/0d6213cb93e613284743ee89d19ce66c5135fd04.jpeg)

Many thanks!

---

<div class="post-metadata">

**Author:** ![Will\_Wang](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/will_wang/32/513624_2.png) [@Will\_Wang](https://discourse.mcneel.com/u/Will_Wang)\
**Post date:** [January 24, 2019, 10:45pm UTC](https://discourse.mcneel.com/t/how-to-split-a-tree-by-the-first-index-in-c/77819/2 "2019-01-24T22:45:17Z")

</div>

No really familiar with C# in GH but I’m guessing this is a pattern that could work.

 ![image](https://global.discourse-cdn.com/mcneel/original/3X/e/9/e9f7ae806f33c768dd3f95935dd3d70592c78040.png)  
I just wanted to piggy-back on my own question:  
Can anyone tell me how to get the output from generic list to actual contents GH can understand?

---

<div class="post-metadata">

**Author:** ![Mahdiyar](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/mahdiyar/32/472862_2.png) [@Mahdiyar](https://discourse.mcneel.com/u/Mahdiyar)\
**Post date:** [January 25, 2019, 6:05am UTC](https://discourse.mcneel.com/t/how-to-split-a-tree-by-the-first-index-in-c/77819/3 "2019-01-25T06:05:38Z")

</div>

@Will_Wang, If you want to append a `list of data items` to the specified branch in the tree, you’d better use [AddRange](https://developer.rhino3d.com/api/grasshopper/html/M_Grasshopper_DataTree_1_AddRange_1.htm) instead of `Add`.

 ![Baris](https://global.discourse-cdn.com/mcneel/original/3X/2/e/2e802b4d0357e3343d09b3bb64efc07265b8fde2.png)  
[Baris.gh](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/c/3/c3dccab58e762f991ccdbd66c597b9e7b0eca5e2.gh) (18.8 KB)

---

<div class="post-metadata">

**Author:** ![Mahdiyar](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/mahdiyar/32/472862_2.png) [@Mahdiyar](https://discourse.mcneel.com/u/Mahdiyar)\
**Post date:** [January 25, 2019, 6:19am UTC](https://discourse.mcneel.com/t/how-to-split-a-tree-by-the-first-index-in-c/77819/4 "2019-01-25T06:19:10Z")

</div>

If you prefer to use `Add`, you have to manually iterate over all the items in the specified branch.

 ![Will_Wang](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/c/3/c3c59785b9f0d0ec9a5632565f443135230f4361.png)  
[Will\_Wang.gh](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/7/2/729968cd0bbf01d561938cde00debce5ff7c5faf.gh) (18.9 KB)

---

<div class="post-metadata">

**Author:** ![Baris](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/baris/32/759711_2.png) [@Baris](https://discourse.mcneel.com/u/Baris)\
**Post date:** [January 25, 2019, 1:32pm UTC](https://discourse.mcneel.com/t/how-to-split-a-tree-by-the-first-index-in-c/77819/5 "2019-01-25T13:32:01Z")

</div>

Thanks @Mahdiyar
