NList is an implementation of the List collection that allows you to modify the list while enumerating, and to iterate without generating garbage. This means you can have a list of objects and add/remove objects on-the-go, although you will need to be careful how to use this.

Using an NList

Using NList is almost identical to the List collection class provided in C#. The only change is in the enumeration of items.
            NList<object> list = new NList<object>();
            object obj = new object();

            list.Add( obj );
            list.Remove( obj );

            // Begin and End must be called in order to Add()/Remove() objects during the enumeration. The enumeration must also be done on the list.Items property rather than the list itself.
            foreach( object obj in list.Items )
                 // ... code ...

Last edited Feb 7, 2011 at 11:08 AM by twohalf, version 1


No comments yet.