An example of writing and working codes C# using lists of lists List<List<int>>

Hello, Guys

i am developing a plugin for sorting length, i am new to c #
I got that in the main class, there is a method that returns a list of lists and in the grasshopper, at the exit from the node, this output outputs null values

here is an error when the node is working

this is how this output is described in the class of outputs in the node

pManager.AddIntegerParameter(“Len”, “Len”, “Length”, GH_ParamAccess.list);

this is how this method in the class processes and forms a list of lists

List<List<int>> Length1 = Length.GetLength();

the problem is that in the output it is impossible to display these lists of lists by branches of the grasshopper tree

DA.SetDataList(0, Length);

Hi @AlexWer,

For what you are trying to output, you are trying to output a tree.


and for the conversion:

GH_Structure<GH_Integer> tree = new GH_Structure<GH_Integer>();
for(int i = 0; i < List.Count;i++)
    tree.AppendRange(List[i].Select(j=>new GH_Integer(j)), new GH_Path(new int[]{0,i}));
1 Like

christopher.ho Thank you very much for your answer !!!

I kind of did as you wrote, but the development environment gives errors

I made the conclusion from the component

pManager.AddIntegerParameter(“Len”, “Len”, “Length”, GH_ParamAccess.tree);

this is how I did the conversion, but the environment throws errors (((

GH_Structure<GH_Integer> Length = new GH_Structure<GH_Integer>
for(int i = 0; i < List.Count;i++)
Length.AppendRange(List[i].Select(j=>new GH_Integer(j)), new GH_Path(new int{0,i}));

Typo on my part.
Should be the following:
GH_Structure<GH_Integer> Length = new GH_Structure<GH_Integer>();

1 Like

I did this, but he keeps writing errors and how I understood that with lists of lists I’m not so transforming

у меня вот так сейчас

but the list of lists has already been announced earlier ((


these are the error codes

the GH_Structure needs to be a new variable.

List is Length

GH_Structure<GH_Integer> Tree= new GH_Structure<GH_Integer>
for(int i = 0; i < Length.Count;i++)
    Tree.AppendRange(Length[i].Select(j=>new GH_Integer(j)), new GH_Path(new int{0,i}));
1 Like

Thank you very much, rays of gratitude, everything worked !!!