Instantiating lists

Like other data structures, lists must be defined and instantiated prior to being used. Each of the four languages that we will examine in this text has varying support for, and unique implementations of, the list data structure. Let's briefly examine how to instantiate a list in each language.

C#

Instantiating lists in C# requires the use of the new keyword:

    //Array backed lists 
    ArrayList myArrayList = new ArrayList(); 
    List<string> myOtherArrayList = new List<string>(); 
 
    //Linked lists 
    LinkedList<string> myLinkedList = new LinkedList<string>(); 

The C# ArrayList class originated in .NET 1.0, and it is not used very often anymore. Most developers prefer to use the generic concrete implementation, List<of T>, for an array-based ...

Get Everyday Data Structures now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.