Putting different data in one single list

Hello guys,

I wonder if there is a way to put different data types (like point & curve) in a single list in Csharp.
Although we can easily do that in grasshopper by the “merge” component, I am still looking for a way to put a point and a curve in a single list.

Hope someone can show me a simple demo code.
Thank you!

You could use List<object>.

List<object> listOfAnything = new List<object>();

listOfAnything.Add(new Point3d(0, 1, 2));
listOfAnything.Add("String");

Note that you’ll have to have code to properly interpret what is at each cell of the list. It is doable with the is keyword in an if-statement.

foreach(object ob in listOfAnything) {
  if(ob is Point3d p) {
    // do something useful
  }
  else if(ob is string s) {
    // useful stuff on a string
  }
}

Note that Grasshopper has its own “generic” class to encapsulate anything: GH_Goo