C# turn object to List<List<int>> again

Do you know what I am doing wrong?
It is originally a List<List>
Can I turn the object to a List<List> again?


202203191333Q.gh (19.6 KB)

This an annoying beauty of grasshopper because you did not input datatree of int. Grasshopper does not know what is a list of lists.

So you must cast them in the code from object to a list of int.

Or if you are lazy, create new c# component write A=x which will convert your lists to a datatree

1 Like

How do you cast an object to a list of int in this situation?
Or is it in the business more usual to import things as datatrees? What means that I should have output the initial data as a datatree in the first place.

A=x; gives me the same input but than as an output.

Set input type object then iteratate lists and cast them i.e. var list = (List < int> )x[i];

1 Like

I don’t understand System.Collectins.Generic.List
I think I have to do something with that.


202203191334Q.gh (7.8 KB)

Seems that you also need to iterate items and cast objects to int.

Also worth to test cast with keyword as.

There are bunch of answers here too:

1 Like

Hi, do you have the origin data for List<List> ?
I did some casting test for you already, but seems like there’s no valid int inside.

Thanks
202203191334A.gh (10.7 KB)

1 Like

grasshopper can’t output list of list or array of array directly otherwise you will get a list of objects. The right way is to use “DataTree” or “GH_Structure”.

1 Like

Learn C# what else?

ListOfList.gh (13.9 KB)

BTW you can’t unbox “straight” an object in a collection - for more than obvious reasons.

BTW: Since long time you have the answer on hand (The catigator case and the likes). But long is the path (and hilly).

1 Like

Your problem is mainly that you converted yout “object” into an actual string.
You probably did something like this:


Passing through a panel convert any object into a plain text!
Check this:

Your “Data” parameter contains nothing more than a simple List of strings/texts.

Your “System.Collections.Generic.List`1[System.Int32]” object are just 47-character-long strings.

1 Like


ListOfLists.gh (7.2 KB)

1 Like

Thank you :grin:

:fearful::cold_sweat::sweat_smile: forgive me, that is so stupid of mine… :point_right:t2:.:point_left:t2::sweat_smile: I internalised it as a string :cold_sweat: thank you :grin::sweat_smile: (me trying to fade out this blunder with emojis)

Wait … attached the wrong thing (blame the state of things in AMG W13 car [F1] that is a 100% pig > how Lewis can grab the 8th crown with this aero disaster ???).

I’ll attach the correct C# soon.

In the mean time get (again) a “general” (of some sort) case:

Collections_TheArtOfPointless_V1A.gh (123.4 KB)

1 Like

For some hardcore machoists. If you like List of List of List of List of int you can wrap that collection into a Tuple of List of List of List of List of int … This allows you to pass it from one component into another as a single object. All you need to do then is cast that single object into a Tuple of List of List of List of List of int and access the collection item. :wink:

1 Like

Not quite so: what if the World is NOT made solely from R/GH? (thus DataTrees are more or less … blah, blah)