O'Reilly logo

C# Data Structures and Algorithms by Marcin Jamro

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Array list

The first data structure that meets this requirement is the array list, which is represented by the ArrayList class from the System.Collections namespace. You can use this class to store big collections of data, to which you can easily add new elements when necessary. Of course, you can also remove them, count items, and find an index of a particular value stored within the array list.

How can you do this? Let's take a look at the following code:

ArrayList arrayList = new ArrayList(); 
arrayList.Add(5); 
arrayList.AddRange(new int[] { 6, -7, 8 }); 
arrayList.AddRange(new object[] { "Marcin", "Mary" }); 
arrayList.Insert(5, 7.8); 

In the first line, a new instance of the ArrayList class is created. Then, you use the Add, AddRange, and ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required