The best data structure is always the Array. Remember that! However, it suffers from a fatal flaw, which prevents its use in many situations... the ability to dynamically resize the array and remove/ append items. This is why Collections are used. Now, .NET offers a large variety of Collection classes (look up the System.Collections namespace) and certain Collections specialized for a particular scenario and type (see System.Collections.Specialized).
However, what about custom collections, for example, one that might hold Person objects ? Prior to .NET 2.0, the only way to create such a collection was to create your own custom Collection. It was a pain to do and the procedure usually involved deriving from CollectionBase or implementing ICollection. If you required for-each iteration, you would also need to implement IEnumerable. With .NET 2.0 came Generics (see System.Collections.Generic), which literally transformed the possibilities of .NET. IMHO, it was the single most important improvement to the framework. LINQ would not have been possible if Generics had not been so well accepted. Therefore, to sum up, the simple solution to your answer is : If the bounds of the collection are fixed and you only need to *fill* it, use an Array. Otherwise, use a Generic List (List<Person>). I will not even consider ArrayLists as a viable option. I have said often that I regard them as a convenience collection for newbies. If you *must* store objects, use a HashTable which is much more optimized in other ways. On Sep 30, 1:20 am, Tom <[email protected]> wrote: > I want to have an array of objects. For example, the class may be > Person, and the properties might be LastName, FirstName, and > PhoneNumber. > > Rather than making an array of objects, can I just have .NET allocate > only what I need, kind of how an ArrayList works? > > Thanks
