NList

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.
            list.BeginEnumeration();
            foreach( object obj in list.Items )
            {
                 // ... code ...
            }
            list.EndEnumeration();

Last edited Feb 7, 2011 at 12:08 PM by twohalf, version 1

Comments

No comments yet.