# How can I get a list as output in C#?

**URL:** <https://discourse.mcneel.com/t/how-can-i-get-a-list-as-output-in-c/150939>\
**Category:** Grasshopper Developer\
**Tags:** windows, c\
**Created:** [November 21, 2022, 9:49am UTC](https://discourse.mcneel.com/t/how-can-i-get-a-list-as-output-in-c/150939 "2022-11-21T09:49:52Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carlos\_Carrasco](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/carlos_carrasco/32/410375_2.png) [@Carlos\_Carrasco](https://discourse.mcneel.com/u/Carlos_Carrasco)\
**Post date:** [November 21, 2022, 9:49am UTC](https://discourse.mcneel.com/t/how-can-i-get-a-list-as-output-in-c/150939/1 "2022-11-21T09:49:52Z")

</div>

New user of Grasshopper 3D here,  
and my problem is that I created a component that generates some Points, this component run 26 times (for example) because I gave him 26 inputs. The thing is I want a list of this 26 ouputs instead of the 26 points because I want to use them all together to iterate through the list for the next component that I’m coding.

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/5/d/4/5d478e1f5237090b7bfb1d3e8112f2d415c3bf12.png)

---

<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:** [November 21, 2022, 10:28am UTC](https://discourse.mcneel.com/t/how-can-i-get-a-list-as-output-in-c/150939/2 "2022-11-21T10:28:43Z")

</div>

> [@Carlos\_Carrasco](#):
>
> I gave him 26 inputs

Declare that input as List.

Anyway ALWAYS post something since problem solving via an Image is not yet invented.

---

<div class="post-metadata">

**Author:** ![Carlos\_Carrasco](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/carlos_carrasco/32/410375_2.png) [@Carlos\_Carrasco](https://discourse.mcneel.com/u/Carlos_Carrasco)\
**Post date:** [November 21, 2022, 10:41am UTC](https://discourse.mcneel.com/t/how-can-i-get-a-list-as-output-in-c/150939/3 "2022-11-21T10:41:25Z")

</div>

I changed the input and I’m still getting an invalid cast  
 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/7/7/6/776abe5f2ecbaea392030f903c11d974c686b77f.png)

This is the Generate Matrix component

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/8/5/7/85733c46a203fe7bea6cdc64ba437ab527fc93de.png)

The Ray | Surface - uv floor output is a Point2d

---

<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:** [November 21, 2022, 10:45am UTC](https://discourse.mcneel.com/t/how-can-i-get-a-list-as-output-in-c/150939/4 "2022-11-21T10:45:16Z")

</div>

Maybe I was not clear enough: POST the C# ( **in a test gh file** ) that refuse to do things. Plus a CLEAR description about what you are after.

---

<div class="post-metadata">

**Author:** ![DanielPiker](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/danielpiker/32/666337_2.png) [@DanielPiker](https://discourse.mcneel.com/u/DanielPiker)\
**Post date:** [November 21, 2022, 11:08am UTC](https://discourse.mcneel.com/t/how-can-i-get-a-list-as-output-in-c/150939/5 "2022-11-21T11:08:18Z")

</div>

It looks like the problem is not with the output of the previous component, but the input of your ‘Generate Matrix’ component.  
In `RegisterInputParams` you need to use `GH_ParamAccess.list` for the param, and in SolveInstance use `GetDataList` instead of GetData.

---

<div class="post-metadata">

**Author:** ![Carlos\_Carrasco](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/carlos_carrasco/32/410375_2.png) [@Carlos\_Carrasco](https://discourse.mcneel.com/u/Carlos_Carrasco)\
**Post date:** [November 21, 2022, 11:23am UTC](https://discourse.mcneel.com/t/how-can-i-get-a-list-as-output-in-c/150939/6 "2022-11-21T11:23:29Z")

</div>

Thank you Daniel,  
but now I get invalid cast Point\>\>Point2d

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/b/3/a/b3a287827f22f89076ed244f3219fad063f78806.png)  
 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/d/a/9/da9afff3f3d06399b8cd23980ea7497383748cfd.png)

---

<div class="post-metadata">

**Author:** ![Carlos\_Carrasco](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/carlos_carrasco/32/410375_2.png) [@Carlos\_Carrasco](https://discourse.mcneel.com/u/Carlos_Carrasco)\
**Post date:** [November 21, 2022, 11:35am UTC](https://discourse.mcneel.com/t/how-can-i-get-a-list-as-output-in-c/150939/7 "2022-11-21T11:35:40Z")

</div>

I’m sorry I don’t think this is the exact thing you want but I don’t know how to upload this in a gh file so I upload the full C# code.  
[GhGenerarMatriz.cs](https://discourse.mcneel.com/uploads/short-url/hW1B6ymjRHmJExx6M7k5fMI7uII.cs) (2.8 KB)

Full Description: I want to generate a Matrix via 2 inputs, these inputs are a list of uv Points and a surface (plane surface). I need the surface to calculate the rows and columns of the matrix.  
With this I want to go though the list to fill the matrix, if there is an uv point {1,1} I want to add +1 to the position [1,1] of the matrix, if there is a {1,2} it will add +1 to the [1,2] position etc.  
This component will call a Method called GenerarMatriz(Points2d, surface) that does this work.

So after this description my problem is that the component Ray | Surface (intersect a ray with a surface) calculates this uv intersection points and I need these points to generate the matrix but when I try to input them I get the invalid cast.

I did this [How can I get a list as output in C#? - #5 by DanielPiker](https://discourse.mcneel.com/t/how-can-i-get-a-list-as-output-in-c/150939/5) but now i get Point\>\>Point2d invalid cast.

---

<div class="post-metadata">

**Author:** ![DanielPiker](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/danielpiker/32/666337_2.png) [@DanielPiker](https://discourse.mcneel.com/u/DanielPiker)\
**Post date:** [November 21, 2022, 11:43am UTC](https://discourse.mcneel.com/t/how-can-i-get-a-list-as-output-in-c/150939/8 "2022-11-21T11:43:48Z")

</div>

Ah, I hadn’t noticed you’re using Point2d.  
Probably the easiest way here is to use `AddPointParameter` instead of Generic, (and `GetDataList<Point3d>`), then you get a list of Point3d (and can just ignore the Z part in the bits you do next).

---

<div class="post-metadata">

**Author:** ![Carlos\_Carrasco](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/carlos_carrasco/32/410375_2.png) [@Carlos\_Carrasco](https://discourse.mcneel.com/u/Carlos_Carrasco)\
**Post date:** [November 21, 2022, 11:49am UTC](https://discourse.mcneel.com/t/how-can-i-get-a-list-as-output-in-c/150939/9 "2022-11-21T11:49:08Z")

</div>

Yes! worked with Point3d.  
Thank you Daniel!

---

<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:** [November 21, 2022, 2:17pm UTC](https://discourse.mcneel.com/t/how-can-i-get-a-list-as-output-in-c/150939/10 "2022-11-21T14:17:16Z")

</div>

Given the opportunity:

1. If you want some sort of “visual map” of a Tree to a Matrix … see comments in the attached.

2. Ray3d DOES not work on BrepFaces … thus see Method used .

[Matrix\_MapCcxPtsTree\_To\_Matrix\_V1.gh](https://discourse.mcneel.com/uploads/short-url/exnJJGb4VbygtwtG3EpDoV9jqOe.gh) (157.9 KB)
