Scripting with generic lists in C#

iI am working with a C # script, using the C # component provided by grasshopper, but I had the following problem: When creating a generic list, it does not recognize it, the System.Collections.Generic assembly is assembled and recognize similar classes as Queue, SortedList , etc, but the List <> class does not recognize it! . How could I solve this?

This is an old issue. David has mentinoned on the old forums that this has to do a lot with the editor - and he has little power over it. As far as I know this has been appointed as a low priority to fix.

My workaround:

1. Remember the important methods/properties of the list class

list.Add(item) // add an item to the list.
list.Count // how many items?
list.IndexOf(item) // what's the index of the item in this list?
list.Remove(item) // remove this exact instance from the list.
list.RemoveAt(index) // remove the item with index 'index'
list.Clear() // remove everything

There are most of the methods/properties of a list that I use - there’s not that much more to it.

2. Use strong type hinting instead of var, or direct access for code completion
e.g.
Instead of

// lets assume you've added a bunch of points to the list..
var list = new List<Point3d>();
// won't autocomplete
list[23].X;

foreach (var pt in list)
{
  // pt won't autocomplete
}

You can use this:

// lets assume you've added a bunch of points to the list..
var list = new List<Point3d>();
// you know it's a point..
Point3d ptA = list[23];

foreach (Point3d pt in list)
{
  // pt will autocomplete
}

Can’t fix it, not my code. So yeah, the editor is really bad at generics and List<T> is the most common generic class. You just have to type it the way it should look and kill the autocomplete with escape whenever it tries to interfere with a List declaration/construction.

thanks for your answers !!!, I found a similar class: "Rhino.Collections.RhinoList ", and it works perfectly !!!